PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
6.3KB

  1. /*
  2. The slight modified adafruit test for his libraries
  3. adapted for this one, shows how simple is deal with it.
  4. */
  5. #include <SPI.h>
  6. #include <RA8875.h>
  7. #define RA8875_CS 10
  8. #define RA8875_RESET 9//any pin or nothing!
  9. RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);
  10. float p = 3.1415926;
  11. void setup()
  12. {
  13. tft.begin(RA8875_800x480);
  14. }
  15. uint8_t rot = 0;
  16. void loop() {
  17. tft.setRotation(rot);
  18. testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", RA8875_WHITE);
  19. delay(1000);
  20. tftPrintTest();
  21. delay(1000);
  22. testlines(RA8875_YELLOW);
  23. delay(500);
  24. testfastlines(RA8875_RED, RA8875_BLUE);
  25. delay(500);
  26. testdrawrects(RA8875_GREEN);
  27. delay(500);
  28. testfillrects(RA8875_YELLOW, RA8875_MAGENTA);
  29. delay(500);
  30. tft.fillWindow();
  31. testfillcircles(10, RA8875_BLUE);
  32. testdrawcircles(10, RA8875_WHITE);
  33. delay(500);
  34. testroundrects();
  35. delay(500);
  36. testtriangles();
  37. delay(500);
  38. mediabuttons();
  39. delay(1000);
  40. if (rot > 3) rot = 0;
  41. rot++;
  42. }
  43. void mediabuttons() {
  44. // play
  45. tft.fillWindow();
  46. tft.fillRoundRect(25, 10, 78, 60, 8, RA8875_WHITE);
  47. tft.fillTriangle(42, 20, 42, 60, 90, 40, RA8875_RED);
  48. delay(500);
  49. // pause
  50. tft.fillRoundRect(25, 90, 78, 60, 8, RA8875_WHITE);
  51. tft.fillRoundRect(39, 98, 20, 45, 5, RA8875_GREEN);
  52. tft.fillRoundRect(69, 98, 20, 45, 5, RA8875_GREEN);
  53. delay(500);
  54. // play color
  55. tft.fillTriangle(42, 20, 42, 60, 90, 40, RA8875_BLUE);
  56. delay(50);
  57. // pause color
  58. tft.fillRoundRect(39, 98, 20, 45, 5, RA8875_RED);
  59. tft.fillRoundRect(69, 98, 20, 45, 5, RA8875_RED);
  60. // play color
  61. tft.fillTriangle(42, 20, 42, 60, 90, 40, RA8875_GREEN);
  62. }
  63. void tftPrintTest() {
  64. tft.fillWindow();
  65. tft.setCursor(0, 30);
  66. tft.setTextColor(RA8875_RED);
  67. tft.setFontScale(1);
  68. tft.println("Hello World!");
  69. tft.setTextColor(RA8875_YELLOW);
  70. tft.setFontScale(2);
  71. tft.println("Hello World!");
  72. tft.setTextColor(RA8875_GREEN);
  73. tft.setFontScale(3);
  74. tft.println("Hello World!");
  75. tft.setTextColor(RA8875_BLUE);
  76. tft.setFontScale(2);
  77. tft.print(1234.567);
  78. delay(1500);
  79. tft.setCursor(0, 0);
  80. tft.fillWindow();
  81. tft.setTextColor(RA8875_WHITE);
  82. tft.setFontScale(0);
  83. tft.println("Hello World!");
  84. tft.setFontScale(1);
  85. tft.setTextColor(RA8875_GREEN);
  86. tft.print(p, 6);
  87. tft.println(" Want pi?");
  88. tft.println(" ");
  89. tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  90. tft.println(" Print HEX!");
  91. tft.println(" ");
  92. tft.setTextColor(RA8875_WHITE);
  93. tft.println("Sketch has been");
  94. tft.println("running for: ");
  95. tft.setTextColor(RA8875_MAGENTA);
  96. tft.print(millis() / 1000);
  97. tft.setTextColor(RA8875_WHITE);
  98. tft.print(" seconds.");
  99. }
  100. void testroundrects() {
  101. tft.fillWindow();
  102. uint16_t color = 100;
  103. uint16_t i;
  104. uint8_t t;
  105. uint16_t x, y, w, h;
  106. for (t = 0 ; t <= 4; t += 1) {
  107. x = 0;
  108. y = 0;
  109. w = tft.width() - 1;
  110. h = tft.height() - 1;
  111. for (i = 0 ; i < tft.width(); i += 1) {
  112. tft.drawRoundRect(x, y, w, h, 5, color);
  113. x += 2;
  114. y += 3;
  115. w -= 4;
  116. h -= 6;
  117. color += 1100;
  118. }
  119. color += 100;
  120. }
  121. }
  122. void testtriangles() {
  123. tft.fillWindow();
  124. uint16_t maxw = tft.width() - 1;
  125. uint16_t maxh = tft.height() - 1;
  126. uint16_t k, t;
  127. for (k = 0; k < 64; k++) {
  128. for (t = 0 ; t <= 30; t += 1) {
  129. tft.fillTriangle(random(0, maxw), random(0, maxh), random(0, maxw), random(0, maxh), random(0, maxw), random(0, maxh), random(0x0000, 0xFFFF));
  130. }
  131. tft.fillWindow();
  132. }
  133. }
  134. void testdrawcircles(uint8_t radius, uint16_t color) {
  135. uint16_t x, y;
  136. for (x = 0; x < tft.width() + radius; x += radius * 2) {
  137. for (y = 0; y < tft.height() + radius; y += radius * 2) {
  138. tft.drawCircle(x, y, radius, color);
  139. }
  140. }
  141. }
  142. void testfillcircles(uint8_t radius, uint16_t color) {
  143. uint16_t x, y;
  144. for (x = radius; x < tft.width(); x += radius * 2) {
  145. for (y = radius; y < tft.height(); y += radius * 2) {
  146. tft.fillCircle(x, y, radius, color);
  147. }
  148. }
  149. }
  150. void testdrawrects(uint16_t color) {
  151. uint16_t x;
  152. uint8_t inc = 2;
  153. uint16_t side;
  154. if (tft.isPortrait()) {
  155. side = tft.width();
  156. } else {
  157. side = tft.height();
  158. }
  159. tft.fillWindow();
  160. for (x = 0; x < side; x += inc) {
  161. tft.drawRect((tft.width() / 2) - (x / 2), (tft.height() / 2) - (x / 2) , x, x, color);
  162. }
  163. }
  164. void testfillrects(uint16_t color1, uint16_t color2) {
  165. uint16_t x = 0;
  166. uint16_t inc = 8;
  167. uint16_t side;
  168. if (tft.isPortrait()) {
  169. side = tft.width();
  170. } else {
  171. side = tft.height();
  172. }
  173. tft.fillWindow();
  174. for (x = side - 1; x > inc; x -= inc) {
  175. tft.fillRect((tft.width() / 2) - (x / 2), (tft.height() / 2) - (x / 2) , x, x, color1);
  176. tft.drawRect((tft.width() / 2) - (x / 2), (tft.height() / 2) - (x / 2) , x, x, color2);
  177. }
  178. }
  179. void testfastlines(uint16_t color1, uint16_t color2) {
  180. uint16_t x, y;
  181. uint8_t inc = 5;
  182. tft.fillWindow(RA8875_BLACK);
  183. for (y = 0; y < tft.height(); y += inc) {
  184. tft.drawFastHLine(0, y, tft.width(), color1);
  185. }
  186. for (x = 0; x < tft.width(); x += inc) {
  187. tft.drawFastVLine(x, 0, tft.height(), color2);
  188. }
  189. }
  190. void testdrawtext(const char *text, uint16_t color) {
  191. tft.fillWindow();
  192. tft.setFontScale(0);
  193. tft.setCursor(0, 0);
  194. tft.setTextColor(color);
  195. tft.print(text);
  196. }
  197. void testlines(uint16_t color) {
  198. uint16_t maxw = tft.width() - 1;
  199. uint16_t maxh = tft.height() - 1;
  200. uint16_t x, y;
  201. uint8_t incr = 3;
  202. tft.fillWindow();
  203. for (x = 0; x < tft.width(); x += incr) {
  204. tft.drawLine(0, 0, x, maxh, color);
  205. }
  206. for (y = 0; y < tft.height(); y += incr) {
  207. tft.drawLine(0, 0, maxw, y, color);
  208. }
  209. tft.fillWindow();
  210. for (x = 0; x < tft.width(); x += incr) {
  211. tft.drawLine(maxw, 0, x, maxh, color);
  212. }
  213. for (y = 0; y < tft.height(); y += incr) {
  214. tft.drawLine(maxw, 0, 0, y, color);
  215. }
  216. tft.fillWindow();
  217. for (x = 0; x < tft.width(); x += incr) {
  218. tft.drawLine(0, maxh, x, 0, color);
  219. }
  220. for (y = 0; y < tft.height(); y += incr) {
  221. tft.drawLine(0, maxh, maxw, y, color);
  222. }
  223. tft.fillWindow();
  224. for (x = 0; x < tft.width(); x += incr) {
  225. tft.drawLine(maxw, maxh, x, 0, color);
  226. }
  227. for (y = 0; y < tft.height(); y += incr) {
  228. tft.drawLine(maxw, maxh, 0, y, color);
  229. }
  230. }