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_480x320.ino (6865B)

      1 // Demo based on:
      2 // UTFT_Demo by Henning Karlsen
      3 // web: http://www.henningkarlsen.com/electronics
      4 /*
      5 
      6  The delay between tests is set to 0. The tests run so fast you will need to
      7  change the WAIT value below to see what is being plotted!
      8  
      9  This sketch uses the GLCD and font 2 only.
     10 
     11  Make sure all the required fonts are loaded by editing the
     12  User_Setup.h file in the TFT_eSPI library folder.
     13 
     14   #########################################################################
     15   ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
     16   ######            TO SELECT THE FONTS YOU USE, SEE ABOVE           ######
     17   #########################################################################
     18  */
     19 
     20 // Delay between demo pages
     21 #define WAIT 0 // Delay between tests, set to 0 to demo speed, 2000 to see what it does!
     22 
     23 #define CENTRE 240
     24 
     25 #include <TFT_eSPI.h> // Hardware-specific library
     26 #include <SPI.h>
     27 
     28 TFT_eSPI tft = TFT_eSPI();                   // Invoke custom library with default width and height
     29 
     30 #define TFT_GREY 0x7BEF
     31 
     32 uint32_t runTime = 0;
     33 
     34 void setup()
     35 {
     36   randomSeed(analogRead(0));
     37   Serial.begin(38400);
     38 // Setup the LCD
     39   tft.init();
     40   tft.setRotation(1);
     41 }
     42 
     43 void loop()
     44 {
     45   int buf[478];
     46   int x, x2;
     47   int y, y2;
     48   int r;
     49 
     50   runTime = millis();
     51 // Clear the screen and draw the frame
     52   tft.fillScreen(TFT_BLACK);
     53 
     54   tft.fillRect(0, 0, 480, 13, TFT_RED);
     55 
     56   tft.fillRect(0, 305, 480, 320, TFT_GREY);
     57   tft.setTextColor(TFT_BLACK,TFT_RED);
     58 
     59   tft.drawCentreString("* TFT_eSPI *", CENTRE, 3, 1);
     60   tft.setTextColor(TFT_YELLOW,TFT_GREY);
     61   tft.drawCentreString("Adapted by Bodmer", CENTRE, 309,1);
     62 
     63   tft.drawRect(0, 14, 479, 305-14, TFT_BLUE);
     64 
     65 // Draw crosshairs
     66   tft.drawLine(239, 15, 239, 304, TFT_BLUE);
     67   tft.drawLine(1, 159, 478, 159, TFT_BLUE);
     68   for (int i=9; i<470; i+=10)
     69     tft.drawLine(i, 157, i, 161, TFT_BLUE);
     70   for (int i=19; i<220; i+=10)
     71     tft.drawLine(237, i, 241, i, TFT_BLUE);
     72 
     73 // Draw sin-, cos- and tan-lines  
     74   tft.setTextColor(TFT_CYAN);
     75   tft.drawString("Sin", 5, 15,2);
     76   for (int i=1; i<478; i++)
     77   {
     78     tft.drawPixel(i,159+(sin(((i*1.13)*3.14)/180)*95),TFT_CYAN);
     79   }
     80   
     81   tft.setTextColor(TFT_RED);
     82   tft.drawString("Cos", 5, 30,2);
     83   for (int i=1; i<478; i++)
     84   {
     85     tft.drawPixel(i,159+(cos(((i*1.13)*3.14)/180)*95),TFT_RED);
     86   }
     87 
     88   tft.setTextColor(TFT_YELLOW);
     89   tft.drawString("Tan", 5, 45,2);
     90   for (int i=1; i<478; i++)
     91   {
     92     tft.drawPixel(i,159+(tan(((i*1.13)*3.14)/180)),TFT_YELLOW);
     93   }
     94 
     95   delay(WAIT);
     96 
     97   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
     98   tft.drawLine(239, 15, 239, 304,TFT_BLUE);
     99   tft.drawLine(1, 159, 478, 159,TFT_BLUE);
    100 
    101 // Draw a moving sinewave
    102 int col = 0;
    103   x=1;
    104   for (int i=1; i<(477*15); i++) 
    105   {
    106     x++;
    107     if (x==478)
    108       x=1;
    109     if (i>478)
    110     {
    111       if ((x==239)||(buf[x-1]==159))
    112         col = TFT_BLUE;
    113       else
    114         tft.drawPixel(x,buf[x-1],TFT_BLACK);
    115     }
    116     y=159+(sin(((i*0.7)*3.14)/180)*(90-(i / 100)));
    117     tft.drawPixel(x,y, TFT_BLUE);
    118     buf[x-1]=y;
    119   }
    120 
    121   delay(WAIT);
    122   
    123   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    124 
    125 // Draw some filled rectangles
    126   for (int i=1; i<6; i++)
    127   {
    128     switch (i)
    129     {
    130       case 1:
    131         col = TFT_MAGENTA;
    132         break;
    133       case 2:
    134         col = TFT_RED;
    135         break;
    136       case 3:
    137         col = TFT_GREEN;
    138         break;
    139       case 4:
    140         col = TFT_BLUE;
    141         break;
    142       case 5:
    143         col = TFT_YELLOW;
    144         break;
    145     }
    146     tft.fillRect(150+(i*20), 70+(i*20), 60, 60,col);
    147   }
    148 
    149   delay(WAIT);
    150   
    151   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    152 
    153 // Draw some filled, rounded rectangles
    154   for (int i=1; i<6; i++)
    155   {
    156     switch (i)
    157     {
    158       case 1:
    159         col = TFT_MAGENTA;
    160         break;
    161       case 2:
    162         col = TFT_RED;
    163         break;
    164       case 3:
    165         col = TFT_GREEN;
    166         break;
    167       case 4:
    168         col = TFT_BLUE;
    169         break;
    170       case 5:
    171         col = TFT_YELLOW;
    172         break;
    173     }
    174     tft.fillRoundRect(270-(i*20), 70+(i*20), 60, 60, 3, col);
    175   }
    176   
    177   delay(WAIT);
    178   
    179   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    180 
    181 // Draw some filled circles
    182   for (int i=1; i<6; i++)
    183   {
    184     switch (i)
    185     {
    186       case 1:
    187         col = TFT_MAGENTA;
    188         break;
    189       case 2:
    190         col = TFT_RED;
    191         break;
    192       case 3:
    193         col = TFT_GREEN;
    194         break;
    195       case 4:
    196         col = TFT_BLUE;
    197         break;
    198       case 5:
    199         col = TFT_YELLOW;
    200         break;
    201     }
    202     tft.fillCircle(180+(i*20),100+(i*20), 30,col);
    203   }
    204   
    205   delay(WAIT);
    206   
    207   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    208 
    209 // Draw some lines in a pattern
    210 
    211   for (int i=15; i<304; i+=5)
    212   {
    213     tft.drawLine(1, i, (i*1.6)-10, 303, TFT_RED);
    214   }
    215 
    216   for (int i=304; i>15; i-=5)
    217   {
    218     tft.drawLine(477, i, (i*1.6)-11, 15, TFT_RED);
    219   }
    220 
    221   for (int i=304; i>15; i-=5)
    222   {
    223     tft.drawLine(1, i, 491-(i*1.6), 15, TFT_CYAN);
    224   }
    225 
    226   for (int i=15; i<304; i+=5)
    227   {
    228     tft.drawLine(477, i, 490-(i*1.6), 303, TFT_CYAN);
    229   }
    230   
    231   delay(WAIT);
    232   
    233   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    234 
    235 // Draw some random circles
    236   for (int i=0; i<100; i++)
    237   {
    238     x=32+random(416);
    239     y=45+random(226);
    240     r=random(30);
    241     tft.drawCircle(x, y, r,random(0xFFFF));
    242   }
    243 
    244   delay(WAIT);
    245   
    246   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    247 
    248 // Draw some random rectangles
    249   for (int i=0; i<100; i++)
    250   {
    251     x=2+random(476);
    252     y=16+random(289);
    253     x2=2+random(476);
    254     y2=16+random(289);
    255     if (x2<x) {
    256       r=x;x=x2;x2=r;
    257     }
    258     if (y2<y) {
    259       r=y;y=y2;y2=r;
    260     }
    261     tft.drawRect(x, y, x2-x, y2-y,random(0xFFFF));
    262   }
    263 
    264   delay(WAIT);
    265   
    266   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    267 
    268 // Draw some random rounded rectangles
    269   for (int i=0; i<100; i++)
    270   {
    271     x=2+random(476);
    272     y=16+random(289);
    273     x2=2+random(476);
    274     y2=16+random(289);
    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     tft.drawRoundRect(x, y, x2-x, y2-y, 3,random(0xFFFF));
    282   }
    283 
    284   delay(WAIT);
    285   
    286   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    287 
    288   for (int i=0; i<100; i++)
    289   {
    290     x=2+random(476);
    291     y=16+random(289);
    292     x2=2+random(476);
    293     y2=16+random(289);
    294     col=random(0xFFFF);
    295     tft.drawLine(x, y, x2, y2,col);
    296   }
    297 
    298   delay(WAIT);
    299   
    300   tft.fillRect(1,15,478-1,304-15,TFT_BLACK);
    301 
    302   for (int i=0; i<10000; i++)
    303   {
    304     tft.drawPixel(2+random(476), 16+random(289),random(0xFFFF));
    305   }
    306 
    307   delay(WAIT);
    308 
    309   tft.fillRect(0, 0, 480, 320, TFT_BLUE);
    310 
    311   tft.fillRoundRect(160, 70, 319-160, 169-70, 3,TFT_RED);
    312   
    313   tft.setTextColor(TFT_WHITE,TFT_RED);
    314   tft.drawCentreString("That's it!", CENTRE, 93,2);
    315   tft.drawCentreString("Restarting in a", CENTRE, 119, 2);
    316   tft.drawCentreString("few seconds...", CENTRE, 132, 2);
    317 
    318   tft.setTextColor(TFT_GREEN,TFT_BLUE);
    319   tft.drawCentreString("Runtime: (msecs)", CENTRE, 280, 2);
    320   tft.setTextDatum(TC_DATUM);
    321   runTime = millis()-runTime;
    322   tft.drawNumber(runTime, CENTRE, 300,2);
    323   tft.setTextDatum(TL_DATUM);
    324   delay (10000);
    325 }
    326