acidportal

- 😈 Worlds smallest Evil Portal on a LilyGo T-QT
git clone git://git.acid.vegas/acidportal.git
Log | Files | Refs | Archive | README | LICENSE

TFT_graphicstest_small.ino (7047B)

      1 /*
      2  Adapted from the Adafruit graphicstest sketch.
      3 
      4  This sketch uses the GLCD font (font 1) only. Disable other fonts to make
      5  the sketch fit in an UNO!
      6 
      7  Make sure all the display driver and pin connections are correct by
      8  editing the User_Setup.h file in the TFT_eSPI library folder.
      9 
     10  Note that yield() or delay(0) must be called in long duration for/while
     11  loops to stop the ESP8266 watchdog triggering.
     12 
     13  #########################################################################
     14  ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
     15  #########################################################################
     16  */
     17 
     18 
     19 #include <TFT_eSPI.h> // Hardware-specific library
     20 #include <SPI.h>
     21 
     22 TFT_eSPI tft = TFT_eSPI();       // Invoke custom library
     23 
     24 float p = 3.1415926;
     25 
     26 void setup(void) {
     27   Serial.begin(9600);
     28   Serial.print("Hello! ST7735 TFT Test");
     29 
     30   // Use this initializer if you're using a 1.8" TFT
     31   tft.init();   // initialize a ST7735S chip
     32 
     33   Serial.println("Initialized");
     34 
     35   uint16_t time = millis();
     36   tft.fillScreen(TFT_BLACK);
     37   time = millis() - time;
     38 
     39   Serial.println(time, DEC);
     40   delay(500);
     41 
     42   // large block of text
     43   tft.fillScreen(TFT_BLACK);
     44   testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", TFT_WHITE);
     45   delay(1000);
     46 
     47   // tft print function!
     48   tftPrintTest();
     49   delay(4000);
     50 
     51   // a single pixel
     52   tft.drawPixel(tft.width()/2, tft.height()/2, TFT_GREEN);
     53   delay(500);
     54 
     55   // line draw test
     56   testlines(TFT_YELLOW);
     57   delay(500);
     58 
     59   // optimized lines
     60   testfastlines(TFT_RED, TFT_BLUE);
     61   delay(500);
     62 
     63   testdrawrects(TFT_GREEN);
     64   delay(500);
     65 
     66   testfillrects(TFT_YELLOW, TFT_MAGENTA);
     67   delay(500);
     68 
     69   tft.fillScreen(TFT_BLACK);
     70   testfillcircles(10, TFT_BLUE);
     71   testdrawcircles(10, TFT_WHITE);
     72   delay(500);
     73 
     74   testroundrects();
     75   delay(500);
     76 
     77   testtriangles();
     78   delay(500);
     79 
     80   mediabuttons();
     81   delay(500);
     82 
     83   Serial.println("done");
     84   delay(1000);
     85 }
     86 
     87 void loop() {
     88   tft.invertDisplay(true);
     89   delay(500);
     90   tft.invertDisplay(false);
     91   delay(500);
     92 }
     93 
     94 void testlines(uint16_t color) {
     95   tft.fillScreen(TFT_BLACK);
     96   for (int16_t x=0; x < tft.width(); x+=6) {
     97     tft.drawLine(0, 0, x, tft.height()-1, color);
     98   }
     99   for (int16_t y=0; y < tft.height(); y+=6) {
    100     tft.drawLine(0, 0, tft.width()-1, y, color);
    101   }
    102 
    103   tft.fillScreen(TFT_BLACK);
    104   for (int16_t x=0; x < tft.width(); x+=6) {
    105     tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
    106   }
    107   for (int16_t y=0; y < tft.height(); y+=6) {
    108     tft.drawLine(tft.width()-1, 0, 0, y, color);
    109   }
    110 
    111   tft.fillScreen(TFT_BLACK);
    112   for (int16_t x=0; x < tft.width(); x+=6) {
    113     tft.drawLine(0, tft.height()-1, x, 0, color);
    114   }
    115   for (int16_t y=0; y < tft.height(); y+=6) {
    116     tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
    117   }
    118 
    119   tft.fillScreen(TFT_BLACK);
    120   for (int16_t x=0; x < tft.width(); x+=6) {
    121     tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
    122   }
    123   for (int16_t y=0; y < tft.height(); y+=6) {
    124     tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
    125   }
    126 }
    127 
    128 void testdrawtext(char *text, uint16_t color) {
    129   tft.setCursor(0, 0);
    130   tft.setTextColor(color);
    131   tft.setTextWrap(true);
    132   tft.print(text);
    133 }
    134 
    135 void testfastlines(uint16_t color1, uint16_t color2) {
    136   tft.fillScreen(TFT_BLACK);
    137   for (int16_t y=0; y < tft.height(); y+=5) {
    138     tft.drawFastHLine(0, y, tft.width(), color1);
    139   }
    140   for (int16_t x=0; x < tft.width(); x+=5) {
    141     tft.drawFastVLine(x, 0, tft.height(), color2);
    142   }
    143 }
    144 
    145 void testdrawrects(uint16_t color) {
    146   tft.fillScreen(TFT_BLACK);
    147   for (int16_t x=0; x < tft.width(); x+=6) {
    148     tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
    149   }
    150 }
    151 
    152 void testfillrects(uint16_t color1, uint16_t color2) {
    153   tft.fillScreen(TFT_BLACK);
    154   for (int16_t x=tft.width()-1; x > 6; x-=6) {
    155     tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
    156     tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
    157   }
    158 }
    159 
    160 void testfillcircles(uint8_t radius, uint16_t color) {
    161   for (int16_t x=radius; x < tft.width(); x+=radius*2) {
    162     for (int16_t y=radius; y < tft.height(); y+=radius*2) {
    163       tft.fillCircle(x, y, radius, color);
    164     }
    165   }
    166 }
    167 
    168 void testdrawcircles(uint8_t radius, uint16_t color) {
    169   for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
    170     for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
    171       tft.drawCircle(x, y, radius, color);
    172     }
    173   }
    174 }
    175 
    176 void testtriangles() {
    177   tft.fillScreen(TFT_BLACK);
    178   int color = 0xF800;
    179   int t;
    180   int w = tft.width()/2;
    181   int x = tft.height()-1;
    182   int y = 0;
    183   int z = tft.width();
    184   for(t = 0 ; t <= 15; t+=1) {
    185     tft.drawTriangle(w, y, y, x, z, x, color);
    186     x-=4;
    187     y+=4;
    188     z-=4;
    189     color+=100;
    190   }
    191 }
    192 
    193 void testroundrects() {
    194   tft.fillScreen(TFT_BLACK);
    195   int color = 100;
    196   int i;
    197   int t;
    198   for(t = 0 ; t <= 4; t+=1) {
    199     int x = 0;
    200     int y = 0;
    201     int w = tft.width()-2;
    202     int h = tft.height()-2;
    203     for(i = 0 ; i <= 16; i+=1) {
    204       tft.drawRoundRect(x, y, w, h, 5, color);
    205       x+=2;
    206       y+=3;
    207       w-=4;
    208       h-=6;
    209       color+=1100;
    210     }
    211     color+=100;
    212   }
    213 }
    214 
    215 void tftPrintTest() {
    216   tft.setTextWrap(false);
    217   tft.fillScreen(TFT_BLACK);
    218   tft.setCursor(0, 30);
    219   tft.setTextColor(TFT_RED);
    220   tft.setTextSize(1);
    221   tft.println("Hello World!");
    222   tft.setTextColor(TFT_YELLOW);
    223   tft.setTextSize(2);
    224   tft.println("Hello World!");
    225   tft.setTextColor(TFT_GREEN);
    226   tft.setTextSize(3);
    227   tft.println("Hello World!");
    228   tft.setTextColor(TFT_BLUE);
    229   tft.setTextSize(4);
    230   tft.print(1234.567);
    231   delay(1500);
    232   tft.setCursor(0, 0);
    233   tft.fillScreen(TFT_BLACK);
    234   tft.setTextColor(TFT_WHITE);
    235   tft.setTextSize(0);
    236   tft.println("Hello World!");
    237   tft.setTextSize(1);
    238   tft.setTextColor(TFT_GREEN);
    239   tft.print(p, 6);
    240   tft.println(" Want pi?");
    241   tft.println(" ");
    242   tft.print(8675309, HEX); // print 8,675,309 out in HEX!
    243   tft.println(" Print HEX!");
    244   tft.println(" ");
    245   tft.setTextColor(TFT_WHITE);
    246   tft.println("Sketch has been");
    247   tft.println("running for: ");
    248   tft.setTextColor(TFT_MAGENTA);
    249   tft.print(millis() / 1000);
    250   tft.setTextColor(TFT_WHITE);
    251   tft.print(" seconds.");
    252 }
    253 
    254 void mediabuttons() {
    255   // play
    256   tft.fillScreen(TFT_BLACK);
    257   tft.fillRoundRect(25, 10, 78, 60, 8, TFT_WHITE);
    258   tft.fillTriangle(42, 20, 42, 60, 90, 40, TFT_RED);
    259   delay(500);
    260   // pause
    261   tft.fillRoundRect(25, 90, 78, 60, 8, TFT_WHITE);
    262   tft.fillRoundRect(39, 98, 20, 45, 5, TFT_GREEN);
    263   tft.fillRoundRect(69, 98, 20, 45, 5, TFT_GREEN);
    264   delay(500);
    265   // play color
    266   tft.fillTriangle(42, 20, 42, 60, 90, 40, TFT_BLUE);
    267   delay(50);
    268   // pause color
    269   tft.fillRoundRect(39, 98, 20, 45, 5, TFT_RED);
    270   tft.fillRoundRect(69, 98, 20, 45, 5, TFT_RED);
    271   // play color
    272   tft.fillTriangle(42, 20, 42, 60, 90, 40, TFT_GREEN);
    273 }
    274