PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

265 rindas
6.5KB

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