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_Matrix.ino (2997B)
1 // A fun MATRIX-like screen demo of scrolling 2 // Screen will flicker initially until fully drawn 3 // then scroll smoothly 4 5 // Needs GLCD font 6 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 ######################################################################### 12 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 13 ######################################################################### 14 */ 15 16 #include <TFT_eSPI.h> // Hardware-specific library 17 #include <SPI.h> 18 19 TFT_eSPI tft = TFT_eSPI(); // Invoke custom library 20 21 #define TEXT_HEIGHT 8 // Height of text to be printed and scrolled 22 #define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen) 23 #define TOP_FIXED_AREA 0 // Number of lines in top fixed area (lines counted from top of screen) 24 25 uint16_t yStart = TOP_FIXED_AREA; 26 uint16_t yArea = 320 - TOP_FIXED_AREA - BOT_FIXED_AREA; 27 uint16_t yDraw = 320 - BOT_FIXED_AREA - TEXT_HEIGHT; 28 byte pos[42]; 29 uint16_t xPos = 0; 30 31 void setup() { 32 Serial.begin(115200); 33 randomSeed(analogRead(A0)); 34 tft.init(); 35 tft.setRotation(0); 36 tft.fillScreen(ILI9341_BLACK); 37 setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA); 38 } 39 40 void loop(void) { 41 // First fill the screen with random streaks of characters 42 for (int j = 0; j < 600; j += TEXT_HEIGHT) { 43 for (int i = 0; i < 40; i++) { 44 if (pos[i] > 20) pos[i] -= 3; // Rapid fade initially brightness values 45 if (pos[i] > 0) pos[i] -= 1; // Slow fade later 46 if ((random(20) == 1) && (j<400)) pos[i] = 63; // ~1 in 20 probability of a new character 47 tft.setTextColor(pos[i] << 5, ILI9341_BLACK); // Set the green character brightness 48 if (pos[i] == 63) tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK); // Draw white character 49 xPos += tft.drawChar(random(32, 128), xPos, yDraw, 1); // Draw the character 50 } 51 yDraw = scroll_slow(TEXT_HEIGHT, 14); // Scroll, 14ms per pixel line 52 xPos = 0; 53 } 54 55 //tft.setRotation(2); 56 //tft.setTextColor(63 << 5, ILI9341_BLACK); 57 //tft.drawCentreString("MATRIX",120,60,4); 58 //tft.setRotation(0); 59 60 // Now scroll smoothly forever 61 while (1) {yield(); yDraw = scroll_slow(320,5); }// Scroll 320 lines, 5ms per line 62 63 } 64 65 void setupScrollArea(uint16_t TFA, uint16_t BFA) { 66 tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition 67 tft.writedata(TFA >> 8); 68 tft.writedata(TFA); 69 tft.writedata((320 - TFA - BFA) >> 8); 70 tft.writedata(320 - TFA - BFA); 71 tft.writedata(BFA >> 8); 72 tft.writedata(BFA); 73 } 74 75 int scroll_slow(int lines, int wait) { 76 int yTemp = yStart; 77 for (int i = 0; i < lines; i++) { 78 yStart++; 79 if (yStart == 320 - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA; 80 scrollAddress(yStart); 81 delay(wait); 82 } 83 return yTemp; 84 } 85 86 void scrollAddress(uint16_t VSP) { 87 tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling start address 88 tft.writedata(VSP >> 8); 89 tft.writedata(VSP); 90 } 91 92 93