acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Viewport_graphicstest.ino (10846B)
1 /* 2 This sketch demonstrates the Adafruit graphicstest sketch running in a 3 viewport (aka window) within the TFT screen area. To do this line 37 has 4 been added. Line 39 draws a frame outside the viewport. 5 6 This sketch uses the GLCD font (font 1) only. 7 8 Make sure all the display driver and pin connections are correct by 9 editing the User_Setup.h file in the TFT_eSPI library folder. 10 11 ######################################################################### 12 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 13 ######################################################################### 14 */ 15 16 17 #include "SPI.h" 18 #include "TFT_eSPI.h" 19 20 TFT_eSPI tft = TFT_eSPI(); 21 22 unsigned long total = 0; 23 unsigned long tn = 0; 24 void setup() { 25 Serial.begin(9600); 26 while (!Serial); 27 28 Serial.println(""); Serial.println(""); 29 Serial.println("TFT_eSPI library test!"); 30 31 tft.init(); 32 33 tn = micros(); 34 tft.fillScreen(TFT_BLACK); 35 36 // Create a viewport 220 x 300 pixels 37 tft.setViewport(10,10,220,300); 38 39 tft.frameViewport(TFT_RED, -1); // 1 pixel wide frame around viewport 40 41 yield(); Serial.println(F("Benchmark Time (microseconds)")); 42 43 yield(); Serial.print(F("Screen fill ")); 44 yield(); Serial.println(testFillScreen()); 45 //total+=testFillScreen(); 46 //delay(500); 47 48 yield(); Serial.print(F("Text ")); 49 yield(); Serial.println(testText()); 50 //total+=testText(); 51 //delay(3000); 52 53 yield(); Serial.print(F("Lines ")); 54 yield(); Serial.println(testLines(TFT_CYAN)); 55 //total+=testLines(TFT_CYAN); 56 //delay(500); 57 58 yield(); Serial.print(F("Horiz/Vert Lines ")); 59 yield(); Serial.println(testFastLines(TFT_RED, TFT_BLUE)); 60 //total+=testFastLines(TFT_RED, TFT_BLUE); 61 //delay(500); 62 63 yield(); Serial.print(F("Rectangles (outline) ")); 64 yield(); Serial.println(testRects(TFT_GREEN)); 65 //total+=testRects(TFT_GREEN); 66 //delay(500); 67 68 yield(); Serial.print(F("Rectangles (filled) ")); 69 yield(); Serial.println(testFilledRects(TFT_YELLOW, TFT_MAGENTA)); 70 //total+=testFilledRects(TFT_YELLOW, TFT_MAGENTA); 71 //delay(500); 72 73 yield(); Serial.print(F("Circles (filled) ")); 74 yield(); Serial.println(testFilledCircles(10, TFT_MAGENTA)); 75 //total+= testFilledCircles(10, TFT_MAGENTA); 76 77 yield(); Serial.print(F("Circles (outline) ")); 78 yield(); Serial.println(testCircles(10, TFT_WHITE)); 79 //total+=testCircles(10, TFT_WHITE); 80 //delay(500); 81 82 yield(); Serial.print(F("Triangles (outline) ")); 83 yield(); Serial.println(testTriangles()); 84 //total+=testTriangles(); 85 //delay(500); 86 87 yield(); Serial.print(F("Triangles (filled) ")); 88 yield(); Serial.println(testFilledTriangles()); 89 //total += testFilledTriangles(); 90 //delay(500); 91 92 yield(); Serial.print(F("Rounded rects (outline) ")); 93 yield(); Serial.println(testRoundRects()); 94 //total+=testRoundRects(); 95 //delay(500); 96 97 yield(); Serial.print(F("Rounded rects (filled) ")); 98 yield(); Serial.println(testFilledRoundRects()); 99 //total+=testFilledRoundRects(); 100 //delay(500); 101 102 yield(); Serial.println(F("Done!")); yield(); 103 //Serial.print(F("Total = ")); Serial.println(total); 104 105 //yield();Serial.println(millis()-tn); 106 } 107 108 void loop(void) { 109 for (uint8_t rotation = 0; rotation < 4; rotation++) { 110 tft.setRotation(rotation); 111 tft.resetViewport(); // reset viewport to whole screen 112 tft.fillScreen(TFT_BLACK); // so it can be cleared 113 114 // Create a viewport 220 x 300 pixels 115 tft.setViewport(10,10,220,300); 116 tft.frameViewport(TFT_RED, -1); // 1 pixel wide frame around viewport 117 118 testText(); 119 delay(2000); 120 } 121 } 122 123 124 unsigned long testFillScreen() { 125 unsigned long start = micros(); 126 tft.fillScreen(TFT_BLACK); 127 tft.fillScreen(TFT_RED); 128 tft.fillScreen(TFT_GREEN); 129 tft.fillScreen(TFT_BLUE); 130 tft.fillScreen(TFT_BLACK); 131 return micros() - start; 132 } 133 134 unsigned long testText() { 135 tft.fillScreen(TFT_BLACK); 136 unsigned long start = micros(); 137 tft.setCursor(0, 0); 138 tft.setTextColor(TFT_WHITE); tft.setTextSize(1); 139 tft.println("Hello World!"); 140 tft.setTextColor(TFT_YELLOW); tft.setTextSize(2); 141 tft.println(1234.56); 142 tft.setTextColor(TFT_RED); tft.setTextSize(3); 143 tft.println(0xDEADBEEF, HEX); 144 tft.println(); 145 tft.setTextColor(TFT_GREEN); 146 tft.setTextSize(5); 147 tft.println("Groop"); 148 tft.setTextSize(2); 149 tft.println("I implore thee,"); 150 //tft.setTextColor(TFT_GREEN,TFT_BLACK); 151 tft.setTextSize(1); 152 tft.println("my foonting turlingdromes."); 153 tft.println("And hooptiously drangle me"); 154 tft.println("with crinkly bindlewurdles,"); 155 tft.println("Or I will rend thee"); 156 tft.println("in the gobberwarts"); 157 tft.println("with my blurglecruncheon,"); 158 tft.println("see if I don't!"); 159 return micros() - start; 160 } 161 162 unsigned long testLines(uint16_t color) { 163 unsigned long start, t; 164 int x1, y1, x2, y2, 165 w = tft.width(), 166 h = tft.height(); 167 168 tft.fillScreen(TFT_BLACK); 169 170 x1 = y1 = 0; 171 y2 = h - 1; 172 start = micros(); 173 for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color); 174 x2 = w - 1; 175 for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color); 176 t = micros() - start; // fillScreen doesn't count against timing 177 178 tft.fillScreen(TFT_BLACK); 179 180 x1 = w - 1; 181 y1 = 0; 182 y2 = h - 1; 183 start = micros(); 184 for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color); 185 x2 = 0; 186 for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color); 187 t += micros() - start; 188 189 tft.fillScreen(TFT_BLACK); 190 191 x1 = 0; 192 y1 = h - 1; 193 y2 = 0; 194 start = micros(); 195 for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color); 196 x2 = w - 1; 197 for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color); 198 t += micros() - start; 199 200 tft.fillScreen(TFT_BLACK); 201 202 x1 = w - 1; 203 y1 = h - 1; 204 y2 = 0; 205 start = micros(); 206 for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color); 207 x2 = 0; 208 for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color); 209 210 return micros() - start; 211 } 212 213 unsigned long testFastLines(uint16_t color1, uint16_t color2) { 214 unsigned long start; 215 int x, y, w = tft.width(), h = tft.height(); 216 217 tft.fillScreen(TFT_BLACK); 218 start = micros(); 219 for (y = 0; y < h; y += 5) tft.drawFastHLine(0, y, w, color1); 220 for (x = 0; x < w; x += 5) tft.drawFastVLine(x, 0, h, color2); 221 222 return micros() - start; 223 } 224 225 unsigned long testRects(uint16_t color) { 226 unsigned long start; 227 int n, i, i2, 228 cx = tft.width() / 2, 229 cy = tft.height() / 2; 230 231 tft.fillScreen(TFT_BLACK); 232 n = min(tft.width(), tft.height()); 233 start = micros(); 234 for (i = 2; i < n; i += 6) { 235 i2 = i / 2; 236 tft.drawRect(cx - i2, cy - i2, i, i, color); 237 } 238 239 return micros() - start; 240 } 241 242 unsigned long testFilledRects(uint16_t color1, uint16_t color2) { 243 unsigned long start, t = 0; 244 int n, i, i2, 245 cx = tft.width() / 2 - 1, 246 cy = tft.height() / 2 - 1; 247 248 tft.fillScreen(TFT_BLACK); 249 n = min(tft.width(), tft.height()); 250 for (i = n - 1; i > 0; i -= 6) { 251 i2 = i / 2; 252 start = micros(); 253 tft.fillRect(cx - i2, cy - i2, i, i, color1); 254 t += micros() - start; 255 // Outlines are not included in timing results 256 tft.drawRect(cx - i2, cy - i2, i, i, color2); 257 } 258 259 return t; 260 } 261 262 unsigned long testFilledCircles(uint8_t radius, uint16_t color) { 263 unsigned long start; 264 int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 265 266 tft.fillScreen(TFT_BLACK); 267 start = micros(); 268 for (x = radius; x < w; x += r2) { 269 for (y = radius; y < h; y += r2) { 270 tft.fillCircle(x, y, radius, color); 271 } 272 } 273 274 return micros() - start; 275 } 276 277 unsigned long testCircles(uint8_t radius, uint16_t color) { 278 unsigned long start; 279 int x, y, r2 = radius * 2, 280 w = tft.width() + radius, 281 h = tft.height() + radius; 282 283 // Screen is not cleared for this one -- this is 284 // intentional and does not affect the reported time. 285 start = micros(); 286 for (x = 0; x < w; x += r2) { 287 for (y = 0; y < h; y += r2) { 288 tft.drawCircle(x, y, radius, color); 289 } 290 } 291 292 return micros() - start; 293 } 294 295 unsigned long testTriangles() { 296 unsigned long start; 297 int n, i, cx = tft.width() / 2 - 1, 298 cy = tft.height() / 2 - 1; 299 300 tft.fillScreen(TFT_BLACK); 301 n = min(cx, cy); 302 start = micros(); 303 for (i = 0; i < n; i += 5) { 304 tft.drawTriangle( 305 cx , cy - i, // peak 306 cx - i, cy + i, // bottom left 307 cx + i, cy + i, // bottom right 308 tft.color565(0, 0, i)); 309 } 310 311 return micros() - start; 312 } 313 314 unsigned long testFilledTriangles() { 315 unsigned long start, t = 0; 316 int i, cx = tft.width() / 2 - 1, 317 cy = tft.height() / 2 - 1; 318 319 tft.fillScreen(TFT_BLACK); 320 start = micros(); 321 for (i = min(cx, cy); i > 10; i -= 5) { 322 start = micros(); 323 tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 324 tft.color565(0, i, i)); 325 t += micros() - start; 326 tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 327 tft.color565(i, i, 0)); 328 } 329 330 return t; 331 } 332 333 unsigned long testRoundRects() { 334 unsigned long start; 335 int w, i, i2, 336 cx = tft.width() / 2 - 1, 337 cy = tft.height() / 2 - 1; 338 339 tft.fillScreen(TFT_BLACK); 340 w = min(tft.width(), tft.height()); 341 start = micros(); 342 for (i = 0; i < w; i += 6) { 343 i2 = i / 2; 344 tft.drawRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.color565(i, 0, 0)); 345 } 346 347 return micros() - start; 348 } 349 350 unsigned long testFilledRoundRects() { 351 unsigned long start; 352 int i, i2, 353 cx = tft.width() / 2 - 1, 354 cy = tft.height() / 2 - 1; 355 356 tft.fillScreen(TFT_BLACK); 357 start = micros(); 358 for (i = min(tft.width(), tft.height()); i > 20; i -= 6) { 359 i2 = i / 2; 360 tft.fillRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.color565(0, i, 0)); 361 } 362 363 return micros() - start; 364 } 365 366 /*************************************************** 367 Original Adafruit text: 368 369 This is an example sketch for the Adafruit 2.2" SPI display. 370 This library works with the Adafruit 2.2" TFT Breakout w/SD card 371 ----> http://www.adafruit.com/products/1480 372 373 Check out the links above for our tutorials and wiring diagrams 374 These displays use SPI to communicate, 4 or 5 pins are required to 375 interface (RST is optional) 376 Adafruit invests time and resources providing this open source code, 377 please support Adafruit and open-source hardware by purchasing 378 products from Adafruit! 379 380 Written by Limor Fried/Ladyada for Adafruit Industries. 381 MIT license, all text above must be included in any redistribution 382 ****************************************************/