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_Rainbow.ino (3738B)

      1 /*
      2   An example showing rainbow colours on a 1.8" TFT LCD screen
      3   and to show a basic example of font use.
      4 
      5   Make sure all the display driver and pin connections are correct by
      6   editing the User_Setup.h file in the TFT_eSPI library folder.
      7 
      8   Note that yield() or delay(0) must be called in long duration for/while
      9   loops to stop the ESP8266 watchdog triggering.
     10 
     11   #########################################################################
     12   ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
     13   #########################################################################
     14 */
     15 
     16 #include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
     17 #include <SPI.h>
     18 
     19 TFT_eSPI tft = TFT_eSPI();  // Invoke library, pins defined in User_Setup.h
     20 
     21 unsigned long targetTime = 0;
     22 byte red = 31;
     23 byte green = 0;
     24 byte blue = 0;
     25 byte state = 0;
     26 unsigned int colour = red << 11;
     27 
     28 void setup(void) {
     29   tft.init();
     30   tft.setRotation(1);
     31   tft.fillScreen(TFT_BLACK);
     32 
     33   targetTime = millis() + 1000;
     34 }
     35 
     36 void loop() {
     37 
     38   if (targetTime < millis()) {
     39     targetTime = millis() + 10000;
     40 
     41     // Colour changing state machine
     42     for (int i = 0; i < 160; i++) {
     43       tft.drawFastVLine(i, 0, tft.height(), colour);
     44       switch (state) {
     45         case 0:
     46           green += 2;
     47           if (green == 64) {
     48             green = 63;
     49             state = 1;
     50           }
     51           break;
     52         case 1:
     53           red--;
     54           if (red == 255) {
     55             red = 0;
     56             state = 2;
     57           }
     58           break;
     59         case 2:
     60           blue ++;
     61           if (blue == 32) {
     62             blue = 31;
     63             state = 3;
     64           }
     65           break;
     66         case 3:
     67           green -= 2;
     68           if (green == 255) {
     69             green = 0;
     70             state = 4;
     71           }
     72           break;
     73         case 4:
     74           red ++;
     75           if (red == 32) {
     76             red = 31;
     77             state = 5;
     78           }
     79           break;
     80         case 5:
     81           blue --;
     82           if (blue == 255) {
     83             blue = 0;
     84             state = 0;
     85           }
     86           break;
     87       }
     88       colour = red << 11 | green << 5 | blue;
     89     }
     90 
     91     // The standard ADAFruit font still works as before
     92     tft.setTextColor(TFT_BLACK);
     93     tft.setCursor (12, 5);
     94     tft.print("Original ADAfruit font!");
     95 
     96     // The new larger fonts do not use the .setCursor call, coords are embedded
     97     tft.setTextColor(TFT_BLACK, TFT_BLACK); // Do not plot the background colour
     98 
     99     // Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!)
    100     tft.drawCentreString("Font size 2", 80, 14, 2); // Draw text centre at position 80, 12 using font 2
    101 
    102     //tft.drawCentreString("Font size 2",81,12,2); // Draw text centre at position 80, 12 using font 2
    103 
    104     tft.drawCentreString("Font size 4", 80, 30, 4); // Draw text centre at position 80, 24 using font 4
    105 
    106     tft.drawCentreString("12.34", 80, 54, 6); // Draw text centre at position 80, 24 using font 6
    107 
    108     tft.drawCentreString("12.34 is in font size 6", 80, 92, 2); // Draw text centre at position 80, 90 using font 2
    109 
    110     // Note the x position is the top left of the font!
    111 
    112     // draw a floating point number
    113     float pi = 3.14159; // Value to print
    114     int precision = 3;  // Number of digits after decimal point
    115     int xpos = 50;      // x position
    116     int ypos = 110;     // y position
    117     int font = 2;       // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : a p m
    118     xpos += tft.drawFloat(pi, precision, xpos, ypos, font); // Draw rounded number and return new xpos delta for next print position
    119     tft.drawString(" is pi", xpos, ypos, font); // Continue printing from new x position
    120   }
    121 }
    122 
    123 
    124 
    125 
    126 
    127