acidportal- 😈 Worlds smallest Evil Portal on a LilyGo T-QT |
git clone git://git.acid.vegas/acidportal.git |
Log | Files | Refs | Archive | README | LICENSE |
Sprite_TFT_Rainbow.ino (3986B)
1 /* 2 An example showing rainbow colours on a 160x128 TFT LCD screen 3 and to show a basic example of font use. 4 5 This example plots the text in a sprite then pushes the sprite to the 6 TFT screen. 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 Note that yield() or delay(0) must be called in long duration for/while 12 loops to stop the ESP8266 watchdog triggering. 13 14 ######################################################################### 15 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 16 ######################################################################### 17 */ 18 19 #define IWIDTH 160 20 #define IHEIGHT 128 21 22 #include <TFT_eSPI.h> // Graphics and font library 23 #include <SPI.h> 24 25 TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h 26 27 TFT_eSprite img = TFT_eSprite(&tft); 28 29 unsigned long targetTime = 0; 30 byte red = 31; 31 byte green = 0; 32 byte blue = 0; 33 byte state = 0; 34 unsigned int colour = red << 11; 35 36 void setup(void) { 37 tft.init(); 38 tft.setRotation(1); 39 tft.fillScreen(TFT_BLACK); 40 41 img.createSprite(IWIDTH, IHEIGHT); 42 img.fillSprite(TFT_BLACK); 43 44 targetTime = millis() + 1000; 45 } 46 47 void loop() { 48 49 if (targetTime < millis()) { 50 targetTime = millis() + 100;//10000; 51 52 // Colour changing state machine 53 for (int i = 0; i < 160; i++) { 54 img.drawFastVLine(i, 0, img.height(), colour); 55 switch (state) { 56 case 0: 57 green += 2; 58 if (green == 64) { 59 green = 63; 60 state = 1; 61 } 62 break; 63 case 1: 64 red--; 65 if (red == 255) { 66 red = 0; 67 state = 2; 68 } 69 break; 70 case 2: 71 blue ++; 72 if (blue == 32) { 73 blue = 31; 74 state = 3; 75 } 76 break; 77 case 3: 78 green -= 2; 79 if (green == 255) { 80 green = 0; 81 state = 4; 82 } 83 break; 84 case 4: 85 red ++; 86 if (red == 32) { 87 red = 31; 88 state = 5; 89 } 90 break; 91 case 5: 92 blue --; 93 if (blue == 255) { 94 blue = 0; 95 state = 0; 96 } 97 break; 98 } 99 colour = red << 11 | green << 5 | blue; 100 } 101 102 // The standard ADAFruit font still works as before 103 img.setTextColor(TFT_BLACK); 104 img.setCursor (12, 5); 105 img.print("Original ADAfruit font!"); 106 107 // The new larger fonts do not use the .setCursor call, coords are embedded 108 img.setTextColor(TFT_BLACK, TFT_BLACK); // Do not plot the background colour 109 110 // Overlay the black text on top of the rainbow plot (the advantage of not drawing the background colour!) 111 img.drawCentreString("Font size 2", 80, 14, 2); // Draw text centre at position 80, 12 using font 2 112 113 //img.drawCentreString("Font size 2",81,12,2); // Draw text centre at position 80, 12 using font 2 114 115 img.drawCentreString("Font size 4", 80, 30, 4); // Draw text centre at position 80, 24 using font 4 116 117 img.drawCentreString("12.34", 80, 54, 6); // Draw text centre at position 80, 24 using font 6 118 119 img.drawCentreString("12.34 is in font size 6", 80, 92, 2); // Draw text centre at position 80, 90 using font 2 120 121 // Note the x position is the top left of the font! 122 123 // draw a floating point number 124 float pi = 3.14159; // Value to print 125 int precision = 3; // Number of digits after decimal point 126 int xpos = 50; // x position 127 int ypos = 110; // y position 128 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 129 xpos += img.drawFloat(pi, precision, xpos, ypos, font); // Draw rounded number and return new xpos delta for next print position 130 img.drawString(" is pi", xpos, ypos, font); // Continue printing from new x position 131 132 img.pushSprite(0, 0); 133 } 134 } 135 136 137 138 139 140