PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

drawingTests.ino 4.0KB

vor 3 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. how fast is the RA8875? here's.
  3. */
  4. #include <SPI.h>
  5. #include <RA8875.h>
  6. #define RA8875_CS 10 //see below...
  7. #define RA8875_RESET 9//any pin or nothing!
  8. RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);
  9. void setup()
  10. {
  11. tft.begin(RA8875_800x480);
  12. }
  13. void loop() {
  14. testdrawrects();
  15. testtriangles(false);
  16. testtriangles(true);
  17. randomRect(false);
  18. randomRect(true);
  19. randomCircles(false);
  20. randomCircles(true);
  21. randomLines();
  22. randomPoints();
  23. }
  24. void testdrawrects() {
  25. tft.fillWindow();
  26. for (int k = 0; k < 64; k++) {
  27. for (uint16_t x = 1; x < tft.height(); x += 6) {
  28. uint16_t c1 = random(0x00FF, 0xFFFF);
  29. tft.drawRect((uint16_t)((tft.width() / 2) - (x / 2)), (uint16_t)((tft.height() / 2) - (x / 2)), x, x, c1);
  30. }
  31. }
  32. }
  33. void randomCircles(bool fill) {
  34. tft.fillWindow();
  35. uint8_t k, c;
  36. for (k = 0; k < 32; k++) {
  37. for (c = 0; c < 32; c++) {
  38. // coordinates
  39. uint16_t x = random(0, tft.width() - 1);
  40. uint16_t y = random(0, tft.height() - 1);
  41. uint16_t r = random(1, tft.height() / 2);
  42. if (x - r < 0) r = x;
  43. if (x + r > (tft.width() - 1)) r = (tft.width() - 1) - x;
  44. if (y - r < 0) r = y;
  45. if (y + r > (tft.height() - 1)) r = (tft.height() - 1) - y;
  46. if (fill) {
  47. tft.fillCircle(x, y, r, random(0x0010, 0xFFFF));
  48. }
  49. else {
  50. tft.drawCircle(x, y, r, random(0x00FF, 0xFFFF));
  51. }
  52. }
  53. if (!fill) tft.fillWindow();
  54. }
  55. }
  56. void randomRect(bool fill) {
  57. tft.fillWindow();
  58. uint16_t k, c;
  59. for (k = 0; k < 128; k++) {
  60. for (c = 0; c < 32; c++) {
  61. uint16_t cx, cy, x, y, w, h;
  62. // center
  63. cx = random(0, tft.width() - 1);
  64. cy = random(0, tft.height() - 1);
  65. // size
  66. w = random(1, tft.width() / 3);
  67. h = random(1, tft.height() / 3);
  68. // upper-left
  69. x = cx - w / 2;
  70. y = cy - h / 2;
  71. if (x < 0) x = 0;
  72. if (y < 0) y = 0;
  73. // adjust size
  74. if (x + w >= tft.width()) w = tft.width() - 1 - x;
  75. if (y + h >= tft.height()) h = tft.height() - 1 - y;
  76. if (fill) {
  77. tft.fillRect(x, y, w, h, random(0x0010, 0xFFFF));
  78. }
  79. else {
  80. tft.drawRect(x, y, w, h, random(0x0010, 0xFFFF));
  81. }
  82. }
  83. tft.fillWindow();
  84. }
  85. }
  86. void randomLines() {
  87. tft.fillWindow();
  88. uint16_t k, c;
  89. for (k = 0; k < tft.height(); k++) {
  90. for (c = 0; c < 32; c++) {
  91. uint16_t x1 = random(0, tft.width() - 2);
  92. uint16_t y1 = random(0, tft.height() - 2);
  93. uint16_t x2 = random(0, tft.width() - 1);
  94. uint16_t y2 = random(0, tft.height() - 1);
  95. tft.drawLine(x1, y1, x2, y2, random(0x0010, 0xFFFF));
  96. }
  97. tft.fillWindow();
  98. }
  99. }
  100. void randomPoints() {
  101. tft.fillWindow();
  102. uint16_t k, c;
  103. for (k = 0; k < 62; k++) {
  104. for (c = 0; c < 1000; c++) {
  105. uint16_t x = random(0, tft.width() - 1);
  106. uint16_t y = random(0, tft.height() - 1);
  107. tft.drawPixel(x, y, random(0x0010, 0xFFFF));
  108. }
  109. tft.fillWindow();
  110. }
  111. }
  112. void testtriangles(bool fill) {
  113. tft.fillWindow();
  114. uint16_t p1x, p1y, p2x, p2y, p3x, p3y;
  115. uint16_t colour;
  116. for (uint16_t k = 0; k < 128; k++) {
  117. for (uint16_t t = 0 ; t <= 30; t += 1) {
  118. p1x = random(0, tft.width() - 1); //get a random number 0-319
  119. p1y = random(0, tft.height() - 1); //get a random number 0-239
  120. p2x = random(0, tft.width() - 1); //get a random number 0-319
  121. p2y = random(0, tft.height() - 1); //get a random number 0-239
  122. p3x = random(0, tft.width() - 1); //get a random number 0-319
  123. p3y = random(0, tft.height() - 1); //get a random number 0-239
  124. colour = random(0, 65536); //get a random number 0-65535
  125. //draw the triangle
  126. if (fill) {
  127. tft.fillTriangle(p1x, p1y, p2x, p2y, p3x, p3y, colour);
  128. }
  129. else {
  130. tft.drawTriangle(p1x, p1y, p2x, p2y, p3x, p3y, colour);
  131. }
  132. }
  133. tft.clearScreen();
  134. }
  135. }
  136. uint16_t halveColor(uint16_t rgb) {
  137. return (((rgb & 0b1111100000000000) >> 12) << 11 | ((rgb & 0b0000011111100000) >> 6) << 5 | ((rgb & 0b0000000000011111) >> 1));
  138. }