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.

288 lines
7.8KB

  1. /***************************************************
  2. This is an example sketch for the Adafruit 1.8" SPI display.
  3. This library works with the Adafruit 1.8" TFT Breakout w/SD card
  4. ----> http://www.adafruit.com/products/358
  5. The 1.8" TFT shield
  6. ----> https://www.adafruit.com/product/802
  7. The 1.44" TFT breakout
  8. ----> https://www.adafruit.com/product/2088
  9. as well as Adafruit raw 1.8" TFT display
  10. ----> http://www.adafruit.com/products/618
  11. Check out the links above for our tutorials and wiring diagrams
  12. These displays use SPI to communicate, 4 or 5 pins are required to
  13. interface (RST is optional)
  14. Adafruit invests time and resources providing this open source code,
  15. please support Adafruit and open-source hardware by purchasing
  16. products from Adafruit!
  17. Written by Limor Fried/Ladyada for Adafruit Industries.
  18. MIT license, all text above must be included in any redistribution
  19. ****************************************************/
  20. // This Teensy3 native optimized version requires specific pins
  21. //
  22. #define TFT_SCLK 13 // SCLK can also use pin 14
  23. #define TFT_MOSI 11 // MOSI can also use pin 7
  24. #define TFT_CS 10 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
  25. #define TFT_DC 9 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
  26. #define TFT_RST 8 // RST can use any pin
  27. #define SD_CS 4 // CS for SD card, can use any pin
  28. #include <Adafruit_GFX.h> // Core graphics library
  29. #include <ST7735_t3.h> // Hardware-specific library
  30. #include <ST7789_t3.h> // Hardware-specific library
  31. #include <SPI.h>
  32. ST7735_t3 tft = ST7735_t3(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
  33. // For 1.54" TFT with ST7789
  34. //ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
  35. void setup(void) {
  36. pinMode(SD_CS, INPUT_PULLUP); // keep SD CS high when not using SD card
  37. Serial.begin(9600);
  38. Serial.print("hello!");
  39. // Use this initializer if you're using a 1.8" TFT
  40. tft.initR(INITR_BLACKTAB);
  41. // Use this initializer (uncomment) if you're using a 1.44" TFT
  42. //tft.initR(INITR_144GREENTAB);
  43. // Some 1.44" displays use different memory offsets
  44. // (uncomment)if yours is not working properly
  45. // May need to tweek the offsets
  46. //tft.setRowColStart(32,0);
  47. // Use this initializer (uncomment) if you're using a 1.54" 240x240 TFT
  48. //tft.init(240, 240); // initialize a ST7789 chip, 240x240 pixels
  49. Serial.println("init");
  50. tft.setTextWrap(false); // Allow text to run off right edge
  51. tft.fillScreen(ST7735_BLACK);
  52. Serial.println("This is a test of the rotation capabilities of the TFT library!");
  53. Serial.println("Press <SEND> (or type a character) to advance");
  54. }
  55. void loop(void) {
  56. rotateLine();
  57. rotateText();
  58. rotatePixel();
  59. rotateFastline();
  60. rotateDrawrect();
  61. rotateFillrect();
  62. rotateDrawcircle();
  63. rotateFillcircle();
  64. rotateTriangle();
  65. rotateFillTriangle();
  66. rotateRoundRect();
  67. rotateFillRoundRect();
  68. rotateChar();
  69. rotateString();
  70. }
  71. void rotateText() {
  72. for (uint8_t i=0; i<4; i++) {
  73. tft.fillScreen(ST7735_BLACK);
  74. Serial.println(tft.getRotation(), DEC);
  75. tft.setCursor(0, 30);
  76. tft.setTextColor(ST7735_RED);
  77. tft.setTextSize(1);
  78. tft.println("Hello World!");
  79. tft.setTextColor(ST7735_YELLOW);
  80. tft.setTextSize(2);
  81. tft.println("Hello World!");
  82. tft.setTextColor(ST7735_GREEN);
  83. tft.setTextSize(3);
  84. tft.println("Hello World!");
  85. tft.setTextColor(ST7735_BLUE);
  86. tft.setTextSize(4);
  87. tft.print(1234.567);
  88. while (!Serial.available());
  89. Serial.read(); Serial.read(); Serial.read();
  90. tft.setRotation(tft.getRotation()+1);
  91. }
  92. }
  93. void rotateFillcircle(void) {
  94. for (uint8_t i=0; i<4; i++) {
  95. tft.fillScreen(ST7735_BLACK);
  96. Serial.println(tft.getRotation(), DEC);
  97. tft.fillCircle(10, 30, 10, ST7735_YELLOW);
  98. while (!Serial.available());
  99. Serial.read(); Serial.read(); Serial.read();
  100. tft.setRotation(tft.getRotation()+1);
  101. }
  102. }
  103. void rotateDrawcircle(void) {
  104. for (uint8_t i=0; i<4; i++) {
  105. tft.fillScreen(ST7735_BLACK);
  106. Serial.println(tft.getRotation(), DEC);
  107. tft.drawCircle(10, 30, 10, ST7735_YELLOW);
  108. while (!Serial.available());
  109. Serial.read(); Serial.read(); Serial.read();
  110. tft.setRotation(tft.getRotation()+1);
  111. }
  112. }
  113. void rotateFillrect(void) {
  114. for (uint8_t i=0; i<4; i++) {
  115. tft.fillScreen(ST7735_BLACK);
  116. Serial.println(tft.getRotation(), DEC);
  117. tft.fillRect(10, 20, 10, 20, ST7735_GREEN);
  118. while (!Serial.available());
  119. Serial.read(); Serial.read(); Serial.read();
  120. tft.setRotation(tft.getRotation()+1);
  121. }
  122. }
  123. void rotateDrawrect(void) {
  124. for (uint8_t i=0; i<4; i++) {
  125. tft.fillScreen(ST7735_BLACK);
  126. Serial.println(tft.getRotation(), DEC);
  127. tft.drawRect(10, 20, 10, 20, ST7735_GREEN);
  128. while (!Serial.available());
  129. Serial.read(); Serial.read(); Serial.read();
  130. tft.setRotation(tft.getRotation()+1);
  131. }
  132. }
  133. void rotateFastline(void) {
  134. for (uint8_t i=0; i<4; i++) {
  135. tft.fillScreen(ST7735_BLACK);
  136. Serial.println(tft.getRotation(), DEC);
  137. tft.drawFastHLine(0, 20, tft.width(), ST7735_RED);
  138. tft.drawFastVLine(20, 0, tft.height(), ST7735_BLUE);
  139. while (!Serial.available());
  140. Serial.read(); Serial.read(); Serial.read();
  141. tft.setRotation(tft.getRotation()+1);
  142. }
  143. }
  144. void rotateLine(void) {
  145. for (uint8_t i=0; i<4; i++) {
  146. tft.fillScreen(ST7735_BLACK);
  147. Serial.println(tft.getRotation(), DEC);
  148. tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, ST7735_RED);
  149. while (!Serial.available());
  150. Serial.read(); Serial.read(); Serial.read();
  151. tft.setRotation(tft.getRotation()+1);
  152. }
  153. }
  154. void rotatePixel(void) {
  155. for (uint8_t i=0; i<4; i++) {
  156. tft.fillScreen(ST7735_BLACK);
  157. Serial.println(tft.getRotation(), DEC);
  158. tft.drawPixel(10,20, ST7735_WHITE);
  159. while (!Serial.available());
  160. Serial.read(); Serial.read(); Serial.read();
  161. tft.setRotation(tft.getRotation()+1);
  162. }
  163. }
  164. void rotateTriangle(void) {
  165. for (uint8_t i=0; i<4; i++) {
  166. tft.fillScreen(ST7735_BLACK);
  167. Serial.println(tft.getRotation(), DEC);
  168. tft.drawTriangle(20, 10, 10, 30, 30, 30, ST7735_GREEN);
  169. while (!Serial.available());
  170. Serial.read(); Serial.read(); Serial.read();
  171. tft.setRotation(tft.getRotation()+1);
  172. }
  173. }
  174. void rotateFillTriangle(void) {
  175. for (uint8_t i=0; i<4; i++) {
  176. tft.fillScreen(ST7735_BLACK);
  177. Serial.println(tft.getRotation(), DEC);
  178. tft.fillTriangle(20, 10, 10, 30, 30, 30, ST7735_RED);
  179. while (!Serial.available());
  180. Serial.read(); Serial.read(); Serial.read();
  181. tft.setRotation(tft.getRotation()+1);
  182. }
  183. }
  184. void rotateRoundRect(void) {
  185. for (uint8_t i=0; i<4; i++) {
  186. tft.fillScreen(ST7735_BLACK);
  187. Serial.println(tft.getRotation(), DEC);
  188. tft.drawRoundRect(20, 10, 25, 15, 5, ST7735_BLUE);
  189. while (!Serial.available());
  190. Serial.read(); Serial.read(); Serial.read();
  191. tft.setRotation(tft.getRotation()+1);
  192. }
  193. }
  194. void rotateFillRoundRect(void) {
  195. for (uint8_t i=0; i<4; i++) {
  196. tft.fillScreen(ST7735_BLACK);
  197. Serial.println(tft.getRotation(), DEC);
  198. tft.fillRoundRect(20, 10, 25, 15, 5, ST7735_CYAN);
  199. while (!Serial.available());
  200. Serial.read(); Serial.read(); Serial.read();
  201. tft.setRotation(tft.getRotation()+1);
  202. }
  203. }
  204. void rotateChar(void) {
  205. for (uint8_t i=0; i<4; i++) {
  206. tft.fillScreen(ST7735_BLACK);
  207. Serial.println(tft.getRotation(), DEC);
  208. tft.drawChar(25, 15, 'A', ST7735_WHITE, ST7735_WHITE, 1);
  209. while (!Serial.available());
  210. Serial.read(); Serial.read(); Serial.read();
  211. tft.setRotation(tft.getRotation()+1);
  212. }
  213. }
  214. void rotateString(void) {
  215. for (uint8_t i=0; i<4; i++) {
  216. tft.fillScreen(ST7735_BLACK);
  217. Serial.println(tft.getRotation(), DEC);
  218. tft.setCursor(8, 25);
  219. tft.setTextSize(1);
  220. tft.setTextColor(ST7735_WHITE);
  221. tft.print("Adafruit Industries");
  222. while (!Serial.available());
  223. Serial.read(); Serial.read(); Serial.read();
  224. tft.setRotation(tft.getRotation()+1);
  225. }
  226. }