acidportal- 😈 Worlds smallest Evil Portal on a LilyGo T-QT |
git clone git://git.acid.vegas/acidportal.git |
Log | Files | Refs | Archive | README | LICENSE |
Print_Smooth_Font.ino (5406B)
1 /* 2 Sketch to demonstrate using the print class with smooth fonts, 3 the Smooth fonts are stored in a FLASH program memory array. 4 5 Sketch is written for a 240 x 320 display 6 7 New font files in the .vlw format can be created using the Processing 8 sketch in the library Tools folder. The Processing sketch can convert 9 TrueType fonts in *.ttf or *.otf files. 10 11 The library supports 16 bit unicode characters: 12 https://en.wikipedia.org/wiki/Unicode_font 13 14 The characters supported are in the in the Basic Multilingual Plane: 15 https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane 16 17 Make sure all the display driver and pin connections are correct by 18 editing the User_Setup.h file in the TFT_eSPI library folder. 19 */ 20 21 // The font is stored in an array within a sketch tab. 22 23 // A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI 24 // https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font 25 26 #include "Final_Frontier_28.h" 27 28 // Graphics and font library 29 #include <TFT_eSPI.h> 30 #include <SPI.h> 31 32 TFT_eSPI tft = TFT_eSPI(); // Invoke library 33 34 // ------------------------------------------------------------------------- 35 // Setup 36 // ------------------------------------------------------------------------- 37 void setup(void) { 38 Serial.begin(115200); // Used for messages 39 40 tft.init(); 41 tft.setRotation(1); 42 } 43 44 // ------------------------------------------------------------------------- 45 // Main loop 46 // ------------------------------------------------------------------------- 47 void loop() { 48 // Wrap test at right and bottom of screen 49 tft.setTextWrap(true, true); 50 51 // Font and background colour, background colour is used for anti-alias blending 52 tft.setTextColor(TFT_WHITE, TFT_BLACK); 53 54 // Load the font 55 tft.loadFont(Final_Frontier_28); 56 57 // Display all characters of the font 58 tft.showFont(2000); 59 60 // Set "cursor" at top left corner of display (0,0) 61 // (cursor will move to next line automatically during printing with 'tft.println' 62 // or stay on the line is there is room for the text with tft.print) 63 tft.setCursor(0, 0); 64 65 // Set the font colour to be white with a black background, set text size multiplier to 1 66 tft.setTextColor(TFT_WHITE, TFT_BLACK); 67 68 // We can now plot text on screen using the "print" class 69 tft.println("Hello World!"); 70 71 // Set the font colour to be yellow 72 tft.setTextColor(TFT_YELLOW, TFT_BLACK); 73 tft.println(1234.56); 74 75 // Set the font colour to be red 76 tft.setTextColor(TFT_RED, TFT_BLACK); 77 tft.println((uint32_t)3735928559, HEX); // Should print DEADBEEF 78 79 // Set the font colour to be green with black background 80 tft.setTextColor(TFT_GREEN, TFT_BLACK); 81 tft.println("Anti-aliased font!"); 82 tft.println(""); 83 84 // Test some print formatting functions 85 float fnumber = 123.45; 86 87 // Set the font colour to be blue 88 tft.setTextColor(TFT_BLUE, TFT_BLACK); 89 tft.print("Float = "); tft.println(fnumber); // Print floating point number 90 tft.print("Binary = "); tft.println((int)fnumber, BIN); // Print as integer value in binary 91 tft.print("Hexadecimal = "); tft.println((int)fnumber, HEX); // Print as integer number in Hexadecimal 92 93 // Unload the font to recover used RAM 94 tft.unloadFont(); 95 96 delay(10000); 97 } 98 99 100 // ------------------------------------------------------------------------- 101 // List files in ESP8266 or ESP32 SPIFFS memory 102 // ------------------------------------------------------------------------- 103 void listFiles(void) { 104 Serial.println(); 105 Serial.println("SPIFFS files found:"); 106 107 #ifdef ESP32 108 listDir(SPIFFS, "/", true); 109 #else 110 fs::Dir dir = SPIFFS.openDir("/"); // Root directory 111 String line = "====================================="; 112 113 Serial.println(line); 114 Serial.println(" File name Size"); 115 Serial.println(line); 116 117 while (dir.next()) { 118 String fileName = dir.fileName(); 119 Serial.print(fileName); 120 int spaces = 25 - fileName.length(); // Tabulate nicely 121 if (spaces < 0) spaces = 1; 122 while (spaces--) Serial.print(" "); 123 fs::File f = dir.openFile("r"); 124 Serial.print(f.size()); Serial.println(" bytes"); 125 yield(); 126 } 127 128 Serial.println(line); 129 #endif 130 Serial.println(); 131 delay(1000); 132 } 133 134 #ifdef ESP32 135 void listDir(fs::FS &fs, const char * dirname, uint8_t levels) { 136 Serial.printf("Listing directory: %s\n", dirname); 137 138 fs::File root = fs.open(dirname); 139 if (!root) { 140 Serial.println("Failed to open directory"); 141 return; 142 } 143 if (!root.isDirectory()) { 144 Serial.println("Not a directory"); 145 return; 146 } 147 148 fs::File file = root.openNextFile(); 149 while (file) { 150 151 if (file.isDirectory()) { 152 Serial.print("DIR : "); 153 String fileName = file.name(); 154 Serial.print(fileName); 155 if (levels) { 156 listDir(fs, file.name(), levels - 1); 157 } 158 } else { 159 String fileName = file.name(); 160 Serial.print(" " + fileName); 161 int spaces = 32 - fileName.length(); // Tabulate nicely 162 if (spaces < 1) spaces = 1; 163 while (spaces--) Serial.print(" "); 164 String fileSize = (String) file.size(); 165 spaces = 8 - fileSize.length(); // Tabulate nicely 166 if (spaces < 1) spaces = 1; 167 while (spaces--) Serial.print(" "); 168 Serial.println(fileSize + " bytes"); 169 } 170 171 file = root.openNextFile(); 172 } 173 } 174 #endif 175 // -------------------------------------------------------------------------