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.1KB

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