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 |
UTFT_demo_fast.ino (8607B)
1 // Demo based on: 2 // UTFT_Demo_320x240 by Henning Karlsen 3 // web: http://www.henningkarlsen.com/electronics 4 // 5 /* 6 7 This sketch uses the GLCD and font 2 only. 8 9 Make sure all the display driver and pin connections are correct by 10 editing the User_Setup.h file in the TFT_eSPI library folder. 11 12 Note that yield() or delay(0) must be called in long duration for/while 13 loops to stop the ESP8266 watchdog triggering. 14 15 ######################################################################### 16 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 17 ######################################################################### 18 */ 19 20 #include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip 21 #include <SPI.h> 22 23 TFT_eSPI myGLCD = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h 24 25 #define DELAY 500 26 27 #define TFT_GREY 0x7BEF 28 #define TFT_W 160 29 #define TFT_H 128 30 31 unsigned long runTime = 0; 32 void setup() 33 { 34 randomSeed(analogRead(A0)); 35 // Setup the LCD 36 myGLCD.init(); 37 myGLCD.setRotation(1); 38 } 39 40 void loop() 41 { 42 //randomSeed(millis()); 43 randomSeed(1234); // This ensure test is repeatable with exact same draws each loop 44 int buf[TFT_W - 2]; 45 int x, x2; 46 int y, y2; 47 int r; 48 runTime = millis(); 49 // Clear the screen and draw the frame 50 myGLCD.fillScreen(TFT_BLACK); 51 52 53 myGLCD.fillRect(0, 0, TFT_W - 1, 14, TFT_RED); 54 55 myGLCD.fillRect(0, TFT_H - 14, TFT_W - 1, 14, TFT_GREY); 56 57 myGLCD.setTextColor(TFT_BLACK, TFT_RED); 58 myGLCD.drawCentreString("* TFT_S6D02A1 *", TFT_W / 2, 4, 1); 59 myGLCD.setTextColor(TFT_YELLOW, TFT_GREY); 60 myGLCD.drawCentreString("Adapted by Bodmer", TFT_W / 2, TFT_H - 12, 1); 61 62 myGLCD.drawRect(0, 14, TFT_W - 1, TFT_H - 28, TFT_BLUE); 63 64 // Draw crosshairs 65 myGLCD.drawLine(TFT_W / 2 - 1, 15, TFT_W / 2 - 1, TFT_H - 16, TFT_BLUE); 66 myGLCD.drawLine(1, TFT_H / 2 - 1, TFT_W - 2, TFT_H / 2 - 1, TFT_BLUE); 67 for (int i = 9; i < TFT_W - 1; i += 10) 68 myGLCD.drawLine(i, TFT_H / 2 - 3, i, TFT_H / 2 + 1, TFT_BLUE); 69 for (int i = 19; i < TFT_H - 20; i += 10) 70 myGLCD.drawLine(TFT_W / 2 - 3, i, TFT_W / 2 + 1, i, TFT_BLUE); 71 72 // Draw sin-, cos- and tan-lines 73 myGLCD.setTextColor(TFT_CYAN); 74 myGLCD.drawString("Sin", 5, 15, 2); 75 for (int i = 1; i < TFT_W - 2; i++) 76 { 77 myGLCD.drawPixel(i, TFT_H / 2 - 1 + (sin(((i * 2.26) * 3.14) / 180) * 48), TFT_CYAN); 78 } 79 myGLCD.setTextColor(TFT_RED); 80 myGLCD.drawString("Cos", 5, 30, 2); 81 for (int i = 1; i < TFT_W - 2; i++) 82 { 83 myGLCD.drawPixel(i, TFT_H / 2 - 1 + (cos(((i * 2.26) * 3.14) / 180) * 48), TFT_RED); 84 } 85 myGLCD.setTextColor(TFT_YELLOW); 86 myGLCD.drawString("Tan", 5, 45, 2); 87 for (int i = 1; i < TFT_W - 2; i++) 88 { 89 myGLCD.drawPixel(i, TFT_H / 2 - 1 + (tan(((i * 2.26) * 3.14) / 180)), TFT_YELLOW); 90 } 91 92 delay(DELAY); 93 94 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 95 96 myGLCD.drawLine(TFT_W / 2 - 1, 15, TFT_W / 2 - 1, TFT_H - 16, TFT_BLUE); 97 myGLCD.drawLine(1, TFT_H / 2 - 1, TFT_W - 2, TFT_H / 2 - 1, TFT_BLUE); 98 int col = 0; 99 // Draw a moving sinewave 100 x = 1; 101 for (int i = 1; i < ((TFT_W - 3) * 20); i++) 102 { 103 x++; 104 if (x == TFT_W - 2) 105 x = 1; 106 if (i > TFT_W - 2) 107 { 108 if ((x == TFT_W / 2 - 1) || (buf[x - 1] == TFT_H / 2 - 1)) 109 col = TFT_BLUE; 110 else 111 myGLCD.drawPixel(x, buf[x - 1], TFT_BLACK); 112 } 113 y = TFT_H / 2 + (sin(((i * 2.2) * 3.14) / 180) * (49 - (i / 100))); 114 myGLCD.drawPixel(x, y, TFT_BLUE); 115 buf[x - 1] = y; 116 } 117 118 delay(DELAY); 119 120 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 121 122 // Draw some filled rectangles 123 for (int i = 1; i < 6; i++) 124 { 125 switch (i) 126 { 127 case 1: 128 col = TFT_MAGENTA; 129 break; 130 case 2: 131 col = TFT_RED; 132 break; 133 case 3: 134 col = TFT_GREEN; 135 break; 136 case 4: 137 col = TFT_BLUE; 138 break; 139 case 5: 140 col = TFT_YELLOW; 141 break; 142 } 143 myGLCD.fillRect(30 + (i * 10), 20 + (i * 10), 30, 30, col); 144 } 145 146 delay(DELAY); 147 148 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 149 150 // Draw some filled, rounded rectangles 151 for (int i = 1; i < 6; i++) 152 { 153 switch (i) 154 { 155 case 1: 156 col = TFT_MAGENTA; 157 break; 158 case 2: 159 col = TFT_RED; 160 break; 161 case 3: 162 col = TFT_GREEN; 163 break; 164 case 4: 165 col = TFT_BLUE; 166 break; 167 case 5: 168 col = TFT_YELLOW; 169 break; 170 } 171 myGLCD.fillRoundRect(TFT_W / 2 + 20 - (i * 10), 20 + (i * 10), 30, 30, 3, col); 172 } 173 174 delay(DELAY); 175 176 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 177 178 // Draw some filled circles 179 for (int i = 1; i < 6; i++) 180 { 181 switch (i) 182 { 183 case 1: 184 col = TFT_MAGENTA; 185 break; 186 case 2: 187 col = TFT_RED; 188 break; 189 case 3: 190 col = TFT_GREEN; 191 break; 192 case 4: 193 col = TFT_BLUE; 194 break; 195 case 5: 196 col = TFT_YELLOW; 197 break; 198 } 199 myGLCD.fillCircle(45 + (i * 10), 30 + (i * 10), 15, col); 200 } 201 202 delay(DELAY); 203 204 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 205 206 // Draw some lines in a pattern 207 208 for (int i = 15; i < TFT_H - 16; i += 5) 209 { 210 myGLCD.drawLine(1, i, (i * 1.44) - 10, TFT_H - 17, TFT_RED); 211 } 212 213 for (int i = TFT_H - 17; i > 15; i -= 5) 214 { 215 myGLCD.drawLine(TFT_W - 3, i, (i * 1.44) - 11, 15, TFT_RED); 216 } 217 218 for (int i = TFT_H - 17; i > 15; i -= 5) 219 { 220 myGLCD.drawLine(1, i, TFT_W + 11 - (i * 1.44), 15, TFT_CYAN); 221 } 222 223 for (int i = 15; i < TFT_H - 16; i += 5) 224 { 225 myGLCD.drawLine(TFT_W - 3, i, TFT_W + 10 - (i * 1.44), TFT_H - 17, TFT_CYAN); 226 } 227 228 delay(DELAY); 229 230 231 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 232 233 // Draw some random circles 234 for (int i = 0; i < 100; i++) 235 { 236 x = 32 + random(TFT_W - 2 - 32 - 30); 237 y = 45 + random(TFT_H - 19 - 45 - 30); 238 r = random(30); 239 myGLCD.drawCircle(x, y, r, random(0xFFFF)); 240 } 241 242 delay(DELAY); 243 244 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 245 246 // Draw some random rectangles 247 for (int i = 0; i < 100; i++) 248 { 249 x = 2 + random(TFT_W - 4); 250 y = 16 + random(TFT_H - 33); 251 x2 = 2 + random(TFT_H - 4); 252 y2 = 16 + random(TFT_H - 33); 253 if (x2 < x) { 254 r = x; x = x2; x2 = r; 255 } 256 if (y2 < y) { 257 r = y; y = y2; y2 = r; 258 } 259 myGLCD.drawRect(x, y, x2 - x, y2 - y, random(0xFFFF)); 260 } 261 262 delay(DELAY); 263 264 265 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 266 267 // Draw some random rounded rectangles 268 for (int i = 0; i < 100; i++) 269 { 270 x = 2 + random(TFT_W - 4); 271 y = 16 + random(TFT_H - 33); 272 x2 = 2 + random(TFT_W - 4); 273 y2 = 16 + random(TFT_H - 33); 274 // We need to get the width and height and do some window checking 275 if (x2 < x) { 276 r = x; x = x2; x2 = r; 277 } 278 if (y2 < y) { 279 r = y; y = y2; y2 = r; 280 } 281 // We need a minimum size of 6 282 if ((x2 - x) < 6) x2 = x + 6; 283 if ((y2 - y) < 6) y2 = y + 6; 284 myGLCD.drawRoundRect(x, y, x2 - x, y2 - y, 3, random(0xFFFF)); 285 } 286 287 delay(DELAY); 288 289 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 290 291 //randomSeed(1234); 292 int colour = 0; 293 for (int i = 0; i < 100; i++) 294 { 295 x = 2 + random(TFT_W - 4); 296 y = 16 + random(TFT_H - 31); 297 x2 = 2 + random(TFT_W - 4); 298 y2 = 16 + random(TFT_H - 31); 299 colour = random(0xFFFF); 300 myGLCD.drawLine(x, y, x2, y2, colour); 301 } 302 303 delay(DELAY); 304 305 myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); 306 307 #define RANDOM 308 309 #ifdef RANDOM 310 // Draw 10,000 pixels 311 // It takes 30ms to calculate the 30,000 random numbers so this is not a true drawPixel speed test 312 for (int i=0; i<10000; i++) 313 { 314 myGLCD.drawPixel(2+random(TFT_W - 3), 16+random(TFT_H - 31),random(0xFFFF)); 315 } 316 #else 317 // Draw 10,000 pixels to fill a 100x100 pixel box, better drawPixel speed test 318 // use the coords as the colour to produce the banding 319 byte i = 100; 320 while (i--) { 321 byte j = 100; 322 while (j--) myGLCD.drawPixel(i + TFT_W / 2 - 50, j + TFT_H / 2 - 50, i + j); 323 } 324 #endif 325 326 delay(DELAY); 327 328 myGLCD.fillScreen(TFT_BLUE); 329 myGLCD.fillRoundRect(20, 20, TFT_W - 40, TFT_H - 60, 6, TFT_RED); 330 331 myGLCD.setTextColor(TFT_WHITE, TFT_RED); 332 myGLCD.drawCentreString("That's it!", TFT_W / 2 - 1, 23, 2); 333 myGLCD.drawCentreString("Restarting in a", TFT_W / 2 - 1, 40, 2); 334 myGLCD.drawCentreString("few seconds...", TFT_W / 2 - 1, 57, 2); 335 336 runTime = millis() - runTime; 337 myGLCD.setTextColor(TFT_GREEN, TFT_BLUE); 338 myGLCD.drawCentreString("Draw time: (msecs)", TFT_W / 2, TFT_H - 34, 2); 339 myGLCD.drawNumber(runTime - 11 * DELAY, TFT_W / 2 - 20, TFT_H - 17, 2); 340 delay (5000); 341 } 342 343