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.

222 lines
3.7KB

  1. /*
  2. An example of how easy it's upload custom 8x16 symbols.
  3. RA8875 has 255 locations reserved for user custom designed symbols.
  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. //define some custom char (8x16)
  11. const uint8_t battery1[16] = {
  12. 0b00111000,
  13. 0b00111000,
  14. 0b11111111,
  15. 0b10000001,
  16. 0b10111101,
  17. 0b10111101,
  18. 0b10111101,
  19. 0b10111101,
  20. 0b10111101,
  21. 0b10111101,
  22. 0b10111101,
  23. 0b10111101,
  24. 0b10111101,
  25. 0b10111101,
  26. 0b10000001,
  27. 0b11111111
  28. };
  29. const uint8_t battery2[16] = {
  30. 0b00111000,
  31. 0b00111000,
  32. 0b11111111,
  33. 0b10000001,
  34. 0b10000001,
  35. 0b10000001,
  36. 0b10111101,
  37. 0b10111101,
  38. 0b10111101,
  39. 0b10111101,
  40. 0b10111101,
  41. 0b10111101,
  42. 0b10111101,
  43. 0b10111101,
  44. 0b10000001,
  45. 0b11111111
  46. };
  47. const uint8_t battery3[16] = {
  48. 0b00111000,
  49. 0b00111000,
  50. 0b11111111,
  51. 0b10000001,
  52. 0b10000001,
  53. 0b10000001,
  54. 0b10000001,
  55. 0b10000001,
  56. 0b10111101,
  57. 0b10111101,
  58. 0b10111101,
  59. 0b10111101,
  60. 0b10111101,
  61. 0b10111101,
  62. 0b10000001,
  63. 0b11111111
  64. };
  65. const uint8_t battery4[16] = {
  66. 0b00111000,
  67. 0b00111000,
  68. 0b11111111,
  69. 0b10000001,
  70. 0b10000001,
  71. 0b10000001,
  72. 0b10000001,
  73. 0b10000001,
  74. 0b10000001,
  75. 0b10000001,
  76. 0b10111101,
  77. 0b10111101,
  78. 0b10111101,
  79. 0b10111101,
  80. 0b10000001,
  81. 0b11111111
  82. };
  83. const uint8_t battery5[16] = {
  84. 0b00111000,
  85. 0b00111000,
  86. 0b11111111,
  87. 0b10000001,
  88. 0b10000001,
  89. 0b10000001,
  90. 0b10000001,
  91. 0b10000001,
  92. 0b10000001,
  93. 0b10000001,
  94. 0b10000001,
  95. 0b10000001,
  96. 0b10000001,
  97. 0b10000001,
  98. 0b10000001,
  99. 0b11111111
  100. };
  101. //next 3 are part of the same char
  102. const uint8_t battery6a[16] = {
  103. 0b00000111,
  104. 0b00000111,
  105. 0b11111111,
  106. 0b11000000,
  107. 0b11000000,
  108. 0b11000000,
  109. 0b11110000,
  110. 0b11111100,
  111. 0b11111111,
  112. 0b11111111,
  113. 0b11111111,
  114. 0b11111111,
  115. 0b11111111,
  116. 0b11111111,
  117. 0b00000000,
  118. 0b00000000
  119. };
  120. const uint8_t battery6b[16] = {
  121. 0b11100000,
  122. 0b11100000,
  123. 0b11111111,
  124. 0b00000011,
  125. 0b00000011,
  126. 0b00000011,
  127. 0b00000011,
  128. 0b00000011,
  129. 0b00000011,
  130. 0b11000011,
  131. 0b11110011,
  132. 0b11111111,
  133. 0b11111111,
  134. 0b11111111,
  135. 0b00000000,
  136. 0b00000000
  137. };
  138. const uint8_t battery6c[16] = {
  139. 0b00011111,
  140. 0b00000011,
  141. 0b00001111,
  142. 0b00000011,
  143. 0b00011111,
  144. 0b00000000,
  145. 0b00011111,
  146. 0b00000011,
  147. 0b00001111,
  148. 0b00000011,
  149. 0b00011111,
  150. 0b00000000,
  151. 0b00000000,
  152. 0b00000000,
  153. 0b00000000,
  154. 0b00000000
  155. };
  156. void setup()
  157. {
  158. uint8_t i;
  159. tft.begin(RA8875_800x480);
  160. //upload chars in address 0x00 to 0x04
  161. tft.uploadUserChar(battery1, 0); //0x00
  162. tft.uploadUserChar(battery2, 1);
  163. tft.uploadUserChar(battery3, 2);
  164. tft.uploadUserChar(battery4, 3);
  165. tft.uploadUserChar(battery5, 4); //0x04
  166. tft.uploadUserChar(battery6a, 5); //
  167. tft.uploadUserChar(battery6b, 6); //
  168. tft.uploadUserChar(battery6c, 7); //
  169. //now custom char are stored in CGRAM
  170. tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  171. tft.setFontScale(0);
  172. for (i = 0; i < 5; i++) {
  173. tft.setCursor(tft.width() / 2, tft.height() / 2);
  174. tft.showUserChar(i);//retrieve from 0x00 to 0x04
  175. delay(200);
  176. }
  177. tft.setFontScale(0);
  178. }
  179. uint8_t rot;
  180. void loop()
  181. {
  182. uint8_t i;
  183. tft.clearScreen();//exact as tft.fillScreen();
  184. tft.setRotation(rot);
  185. tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  186. //custom char are managed as text but need to be called
  187. //by a special function
  188. //the only text parameter that is not accepted is setFontScale!
  189. for (i = 0; i < 5; i++) {
  190. tft.setCursor(10, 10);
  191. tft.showUserChar(i);//retrieve from 0x00 to 0x04
  192. delay(200);
  193. }
  194. //now another feature, you can design a char wider
  195. //by using many char slot combined.
  196. //below an example, 3 chars wider
  197. tft.setTextColor(RA8875_LIGHT_ORANGE);
  198. tft.setCursor(30, 11);
  199. tft.showUserChar(5, 2);
  200. delay(1000);
  201. if (rot > 3) rot = 0;
  202. rot++;
  203. }