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.

ILI9488_FontTest4.ino 6.9KB

3 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #include <Adafruit_GFX.h>
  2. #include <SPI.h>
  3. #include <ILI9488_t3.h>
  4. #include "font_Arial.h"
  5. #include "font_ArialBold.h"
  6. #include "font_ComicSansMS.h"
  7. #include "font_OpenSans.h"
  8. #include "font_DroidSans.h"
  9. #include "font_Michroma.h"
  10. #include "font_Crystal.h"
  11. #include "font_ChanceryItalic.h"
  12. #define CENTER ILI9488_t3::CENTER
  13. // maybe a few GFX FOnts?
  14. #include <Fonts/FreeMono9pt7b.h>
  15. #include <Fonts/FreeSerif9pt7b.h>
  16. typedef struct {
  17. const ILI9488_t3_font_t *ili_font;
  18. const GFXfont *gfx_font;
  19. const char *font_name;
  20. uint16_t font_fg_color;
  21. uint16_t font_bg_color;
  22. } ili_fonts_test_t;
  23. const ili_fonts_test_t font_test_list[] = {
  24. {&Arial_12, nullptr, "Arial_12", ILI9488_WHITE, ILI9488_WHITE},
  25. {&Arial_12_Bold, nullptr, "ArialBold 12", ILI9488_YELLOW, ILI9488_YELLOW},
  26. {&ComicSansMS_12, nullptr, "ComicSansMS 12", ILI9488_GREEN, ILI9488_GREEN},
  27. {&DroidSans_12, nullptr, "DroidSans_12", ILI9488_WHITE, ILI9488_WHITE},
  28. {&Michroma_12, nullptr, "Michroma_12", ILI9488_YELLOW, ILI9488_YELLOW},
  29. {&Crystal_16_Italic, nullptr, "CRYSTAL_16", ILI9488_BLACK, ILI9488_YELLOW},
  30. {&Chancery_16_Italic, nullptr, "Chancery_16_Italic", ILI9488_GREEN, ILI9488_GREEN},
  31. {&OpenSans16, nullptr, "OpenSans 16", ILI9488_RED, ILI9488_YELLOW},
  32. {nullptr, &FreeMono9pt7b, "GFX FreeMono9pt7b", ILI9488_WHITE, ILI9488_WHITE},
  33. {nullptr, &FreeMono9pt7b, "GFX FreeMono9pt7b", ILI9488_RED, ILI9488_YELLOW},
  34. {nullptr, &FreeSerif9pt7b, "GFX FreeSerif9pt7b", ILI9488_WHITE, ILI9488_WHITE},
  35. {nullptr, &FreeSerif9pt7b, "GFX FreeSerif9pt7b", ILI9488_RED, ILI9488_YELLOW},
  36. } ;
  37. #define ILI9488_CS 10
  38. #define ILI9488_DC 9
  39. #define ILI9488_RST 8
  40. ILI9488_t3 tft = ILI9488_t3(&SPI, ILI9488_CS, ILI9488_DC, ILI9488_RST);
  41. uint8_t test_screen_rotation = 0;
  42. void setup() {
  43. Serial.begin(38400);
  44. long unsigned debug_start = millis ();
  45. while (!Serial && ((millis () - debug_start) <= 5000)) ;
  46. Serial.println("Setup");
  47. // begin display: Choose from: ILI9488_480x272, ILI9488_800x480, ILI9488_800x480ALT, Adafruit_480x272, Adafruit_800x480
  48. tft.begin(60000000u);
  49. tft.setRotation(4);
  50. tft.fillScreen(ILI9488_BLACK);
  51. tft.setTextColor(ILI9488_WHITE);
  52. tft.setFont(Arial_12);
  53. tft.println("Arial_12");
  54. displayStuff();
  55. tft.setTextColor(ILI9488_YELLOW);
  56. tft.setFont(Arial_12_Bold);
  57. tft.println("ArialBold 12");
  58. displayStuff();
  59. nextPage();
  60. tft.setTextColor(ILI9488_GREEN);
  61. tft.setFont(ComicSansMS_12);
  62. tft.println("ComicSansMS 12");
  63. displayStuff();
  64. tft.setTextColor(ILI9488_WHITE);
  65. tft.setFont(DroidSans_12);
  66. tft.println("DroidSans_12");
  67. displayStuff();
  68. nextPage();
  69. tft.setTextColor(ILI9488_YELLOW);
  70. tft.setFont(Michroma_12);
  71. tft.println("Michroma_12");
  72. displayStuff();
  73. tft.setTextColor(ILI9488_BLACK, ILI9488_YELLOW);
  74. tft.setFont(Crystal_16_Italic);
  75. tft.println("CRYSTAL_16");
  76. displayStuff();
  77. nextPage();
  78. tft.setTextColor(ILI9488_GREEN);
  79. tft.setFont(Chancery_16_Italic);
  80. tft.println("Chancery_16_Italic");
  81. displayStuff();
  82. //anti-alias font OpenSans
  83. tft.setTextColor(ILI9488_RED, ILI9488_YELLOW);
  84. tft.setFont(OpenSans16);
  85. tft.println("OpenSans 18");
  86. displayStuff();
  87. Serial.println("Basic Font Display Complete");
  88. Serial.println("Loop test for alt colors + font");
  89. }
  90. void loop()
  91. {
  92. tft.setFont(Arial_12);
  93. Serial.printf("\nRotation: %d\n", test_screen_rotation);
  94. tft.setRotation(test_screen_rotation);
  95. tft.fillScreen(ILI9488_RED);
  96. tft.setCursor(CENTER, CENTER);
  97. tft.printf("Rotation: %d", test_screen_rotation);
  98. test_screen_rotation = (test_screen_rotation + 1) & 0x3;
  99. /* tft.setCursor(200, 300);
  100. Serial.printf(" Set cursor(200, 300), retrieved(%d %d)",
  101. tft.getCursorX(), tft.getCursorY());
  102. */
  103. tft.setCursor(25, 25);
  104. tft.write('0');
  105. tft.setCursor(tft.width() - 25, 25);
  106. tft.write('1');
  107. tft.setCursor(25, tft.height() - 25);
  108. tft.write('2');
  109. tft.setCursor(tft.width() - 25, tft.height() - 25);
  110. tft.write('3');
  111. for (uint8_t font_index = 0; font_index < (sizeof(font_test_list) / sizeof(font_test_list[0])); font_index++) {
  112. nextPage();
  113. if (font_test_list[font_index].font_fg_color != font_test_list[font_index].font_bg_color)
  114. tft.setTextColor(font_test_list[font_index].font_fg_color, font_test_list[font_index].font_bg_color);
  115. else
  116. tft.setTextColor(font_test_list[font_index].font_fg_color);
  117. if (font_test_list[font_index].ili_font) tft.setFont(*font_test_list[font_index].ili_font);
  118. else tft.setFont(font_test_list[font_index].gfx_font);
  119. tft.println(font_test_list[font_index].font_name);
  120. displayStuff1();
  121. }
  122. nextPage();
  123. }
  124. uint32_t displayStuff()
  125. {
  126. elapsedMillis elapsed_time = 0;
  127. tft.println("ABCDEFGHIJKLM");
  128. tft.println("nopqrstuvwxyz");
  129. tft.println("0123456789");
  130. tft.println("!@#$%^ &*()-");
  131. tft.println(); tft.println();
  132. return (uint32_t) elapsed_time;
  133. }
  134. uint32_t displayStuff1()
  135. {
  136. elapsedMillis elapsed_time = 0;
  137. tft.println("ABCDEFGHIJKLM");
  138. tft.println("nopqrstuvwxyz");
  139. tft.println("0123456789");
  140. tft.println("!@#$%^ &*()-");
  141. int16_t cursorX = tft.getCursorX();
  142. int16_t cursorY = tft.getCursorY();
  143. uint16_t width = tft.width();
  144. uint16_t height = tft.height();
  145. Serial.printf("DS1 (%d,%d) %d %d\n", cursorX, cursorY, width, height);
  146. uint16_t rect_x = width / 2 - 50;
  147. uint16_t rect_y = height - 50;
  148. tft.drawRect(rect_x, rect_y, 100, 40, ILI9488_WHITE);
  149. for (uint16_t y = rect_y + 5; y < rect_y + 40; y += 5)
  150. tft.drawFastHLine(rect_x + 1, y, 98, ILI9488_PINK);
  151. for (uint16_t x = rect_x + 5; x < rect_x + 100; x += 5)
  152. tft.drawFastVLine(x, rect_y + 1, 38, ILI9488_PINK);
  153. tft.setCursor(width / 2, height - 30, true);
  154. tft.print("Center");
  155. // Lets try again with CENTER X keyword.
  156. rect_y -= 60;
  157. tft.drawRect(rect_x, rect_y, 100, 40, ILI9488_PINK);
  158. for (uint16_t y = rect_y + 5; y < rect_y + 40; y += 5)
  159. tft.drawFastHLine(rect_x + 1, y, 98, ILI9488_CYAN);
  160. for (uint16_t x = rect_x + 5; x < rect_x + 100; x += 5)
  161. tft.drawFastVLine(x, rect_y + 1, 38, ILI9488_CYAN);
  162. tft.setCursor(CENTER, rect_y);
  163. tft.print("XCENTR");
  164. // Lets try again with CENTER Y keyword.
  165. rect_x = 50;
  166. rect_y = tft.height() / 2 - 25;
  167. tft.drawRect(rect_x, rect_y, 100, 50, ILI9488_CYAN);
  168. for (uint16_t y = rect_y + 5; y < rect_y + 50; y += 5)
  169. tft.drawFastHLine(rect_x + 1, y, 98, ILI9488_PINK);
  170. for (uint16_t x = rect_x + 5; x < rect_x + 100; x += 5)
  171. tft.setCursor(50, CENTER);
  172. tft.print("YCENTR");
  173. tft.setCursor(cursorX, cursorY);
  174. static const char alternating_text[] = "AbCdEfGhIjKlM\rNoPqRsTuVwXyZ";
  175. for (uint8_t i = 0; i < (sizeof(alternating_text) - 1); i++) {
  176. if (i & 1) tft.setTextColor(ILI9488_WHITE, ILI9488_RED);
  177. else tft.setTextColor(ILI9488_YELLOW, ILI9488_BLUE);
  178. tft.write(alternating_text[i]);
  179. }
  180. tft.println(); tft.println();
  181. return (uint32_t) elapsed_time;
  182. }
  183. void nextPage()
  184. {
  185. Serial.println("Press anykey to continue");
  186. while (Serial.read() == -1) ;
  187. while (Serial.read() != -1) ;
  188. tft.fillScreen(ILI9488_BLACK);
  189. tft.setCursor(0, 0);
  190. }