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.

259 lines
6.4KB

  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. // begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  14. tft.begin(RA8875_800x480);
  15. }
  16. uint8_t rot = 0;
  17. void loop() {
  18. tft.setRotation(rot);
  19. 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);
  20. delay(1000);
  21. tftPrintTest();
  22. delay(1000);
  23. testlines(RA8875_YELLOW);
  24. delay(500);
  25. testfastlines(RA8875_RED, RA8875_BLUE);
  26. delay(500);
  27. testdrawrects(RA8875_GREEN);
  28. delay(500);
  29. testfillrects(RA8875_YELLOW, RA8875_MAGENTA);
  30. delay(500);
  31. tft.fillWindow();
  32. testfillcircles(10, RA8875_BLUE);
  33. testdrawcircles(10, RA8875_WHITE);
  34. delay(500);
  35. testroundrects();
  36. delay(500);
  37. testtriangles();
  38. delay(500);
  39. mediabuttons();
  40. delay(1000);
  41. if (rot > 3) rot = 0;
  42. rot++;
  43. }
  44. void mediabuttons() {
  45. // play
  46. tft.fillWindow();
  47. tft.fillRoundRect(25, 10, 78, 60, 8, RA8875_WHITE);
  48. tft.fillTriangle(42, 20, 42, 60, 90, 40, RA8875_RED);
  49. delay(500);
  50. // pause
  51. tft.fillRoundRect(25, 90, 78, 60, 8, RA8875_WHITE);
  52. tft.fillRoundRect(39, 98, 20, 45, 5, RA8875_GREEN);
  53. tft.fillRoundRect(69, 98, 20, 45, 5, RA8875_GREEN);
  54. delay(500);
  55. // play color
  56. tft.fillTriangle(42, 20, 42, 60, 90, 40, RA8875_BLUE);
  57. delay(50);
  58. // pause color
  59. tft.fillRoundRect(39, 98, 20, 45, 5, RA8875_RED);
  60. tft.fillRoundRect(69, 98, 20, 45, 5, RA8875_RED);
  61. // play color
  62. tft.fillTriangle(42, 20, 42, 60, 90, 40, RA8875_GREEN);
  63. }
  64. void tftPrintTest() {
  65. tft.fillWindow();
  66. tft.setCursor(0, 30);
  67. tft.setTextColor(RA8875_RED);
  68. tft.setFontScale(1);
  69. tft.println("Hello World!");
  70. tft.setTextColor(RA8875_YELLOW);
  71. tft.setFontScale(2);
  72. tft.println("Hello World!");
  73. tft.setTextColor(RA8875_GREEN);
  74. tft.setFontScale(3);
  75. tft.println("Hello World!");
  76. tft.setTextColor(RA8875_BLUE);
  77. tft.setFontScale(2);
  78. tft.print(1234.567);
  79. delay(1500);
  80. tft.setCursor(0, 0);
  81. tft.fillWindow();
  82. tft.setTextColor(RA8875_WHITE);
  83. tft.setFontScale(0);
  84. tft.println("Hello World!");
  85. tft.setFontScale(1);
  86. tft.setTextColor(RA8875_GREEN);
  87. tft.print(p, 6);
  88. tft.println(" Want pi?");
  89. tft.println(" ");
  90. tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  91. tft.println(" Print HEX!");
  92. tft.println(" ");
  93. tft.setTextColor(RA8875_WHITE);
  94. tft.println("Sketch has been");
  95. tft.println("running for: ");
  96. tft.setTextColor(RA8875_MAGENTA);
  97. tft.print(millis() / 1000);
  98. tft.setTextColor(RA8875_WHITE);
  99. tft.print(" seconds.");
  100. }
  101. void testroundrects() {
  102. tft.fillWindow();
  103. uint16_t color = 100;
  104. uint16_t i;
  105. uint8_t t;
  106. uint16_t x, y, w, h;
  107. for (t = 0 ; t <= 4; t += 1) {
  108. x = 0;
  109. y = 0;
  110. w = tft.width() - 1;
  111. h = tft.height() - 1;
  112. for (i = 0 ; i < tft.width(); i += 1) {
  113. tft.drawRoundRect(x, y, w, h, 5, color);
  114. x += 2;
  115. y += 3;
  116. w -= 4;
  117. h -= 6;
  118. color += 1100;
  119. }
  120. color += 100;
  121. }
  122. }
  123. void testtriangles() {
  124. tft.fillWindow();
  125. uint16_t maxw = tft.width() - 1;
  126. uint16_t maxh = tft.height() - 1;
  127. uint16_t k, t;
  128. for (k = 0; k < 64; k++) {
  129. for (t = 0 ; t <= 30; t += 1) {
  130. tft.fillTriangle(random(0, maxw), random(0, maxh), random(0, maxw), random(0, maxh), random(0, maxw), random(0, maxh), random(0x0000, 0xFFFF));
  131. }
  132. tft.fillWindow();
  133. }
  134. }
  135. void testdrawcircles(uint8_t radius, uint16_t color) {
  136. uint16_t x, y;
  137. for (x = 0; x < tft.width() + radius; x += radius * 2) {
  138. for (y = 0; y < tft.height() + radius; y += radius * 2) {
  139. tft.drawCircle(x, y, radius, color);
  140. }
  141. }
  142. }
  143. void testfillcircles(uint8_t radius, uint16_t color) {
  144. uint16_t x, y;
  145. for (x = radius; x < tft.width(); x += radius * 2) {
  146. for (y = radius; y < tft.height(); y += radius * 2) {
  147. tft.fillCircle(x, y, radius, color);
  148. }
  149. }
  150. }
  151. void testdrawrects(uint16_t color) {
  152. uint16_t x;
  153. uint8_t inc = 2;
  154. uint16_t side;
  155. if (tft.isPortrait()) {
  156. side = tft.width();
  157. } else {
  158. side = tft.height();
  159. }
  160. tft.fillWindow();
  161. for (x = 0; x < side; x += inc) {
  162. tft.drawRect((tft.width() / 2) - (x / 2), (tft.height() / 2) - (x / 2) , x, x, color);
  163. }
  164. }
  165. void testfillrects(uint16_t color1, uint16_t color2) {
  166. uint16_t x = 0;
  167. uint16_t inc = 8;
  168. uint16_t side;
  169. if (tft.isPortrait()) {
  170. side = tft.width();
  171. } else {
  172. side = tft.height();
  173. }
  174. tft.fillWindow();
  175. for (x = side - 1; x > inc; x -= inc) {
  176. tft.fillRect((tft.width() / 2) - (x / 2), (tft.height() / 2) - (x / 2) , x, x, color1);
  177. tft.drawRect((tft.width() / 2) - (x / 2), (tft.height() / 2) - (x / 2) , x, x, color2);
  178. }
  179. }
  180. void testfastlines(uint16_t color1, uint16_t color2) {
  181. uint16_t x, y;
  182. uint8_t inc = 5;
  183. tft.fillWindow(RA8875_BLACK);
  184. for (y = 0; y < tft.height(); y += inc) {
  185. tft.drawFastHLine(0, y, tft.width(), color1);
  186. }
  187. for (x = 0; x < tft.width(); x += inc) {
  188. tft.drawFastVLine(x, 0, tft.height(), color2);
  189. }
  190. }
  191. void testdrawtext(const char *text, uint16_t color) {
  192. tft.fillWindow();
  193. tft.setFontScale(0);
  194. tft.setCursor(0, 0);
  195. tft.setTextColor(color);
  196. tft.print(text);
  197. }
  198. void testlines(uint16_t color) {
  199. uint16_t maxw = tft.width() - 1;
  200. uint16_t maxh = tft.height() - 1;
  201. uint16_t x, y;
  202. uint8_t incr = 3;
  203. tft.fillWindow();
  204. for (x = 0; x < tft.width(); x += incr) {
  205. tft.drawLine(0, 0, x, maxh, color);
  206. }
  207. for (y = 0; y < tft.height(); y += incr) {
  208. tft.drawLine(0, 0, maxw, y, color);
  209. }
  210. tft.fillWindow();
  211. for (x = 0; x < tft.width(); x += incr) {
  212. tft.drawLine(maxw, 0, x, maxh, color);
  213. }
  214. for (y = 0; y < tft.height(); y += incr) {
  215. tft.drawLine(maxw, 0, 0, y, color);
  216. }
  217. tft.fillWindow();
  218. for (x = 0; x < tft.width(); x += incr) {
  219. tft.drawLine(0, maxh, x, 0, color);
  220. }
  221. for (y = 0; y < tft.height(); y += incr) {
  222. tft.drawLine(0, maxh, maxw, y, color);
  223. }
  224. tft.fillWindow();
  225. for (x = 0; x < tft.width(); x += incr) {
  226. tft.drawLine(maxw, maxh, x, 0, color);
  227. }
  228. for (y = 0; y < tft.height(); y += incr) {
  229. tft.drawLine(maxw, maxh, 0, y, color);
  230. }
  231. }