acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Print_Smooth_Font.ino (4922B)
1 /* 2 Sketch to demonstrate using the print class with smooth fonts 3 4 Sketch is written for a 240 x 320 display 5 6 // Upload the fonts and icons to LittleFS (must set at least 1M for LittleFS) using the 7 // "Tools" "ESP8266 LittleFS Data Upload" menu option in the IDE. 8 // To add this option follow instructions here for the ESP8266: 9 // https://github.com/earlephilhower/arduino-esp8266littlefs-plugin 10 11 New font files in the .vlw format can be created using the Processing 12 sketch in the library Tools folder. The Processing sketch can convert 13 TrueType fonts in *.ttf or *.otf files. 14 15 The library supports 16 bit Unicode characters: 16 https://en.wikipedia.org/wiki/Unicode_font 17 18 The characters supported are in the in the Basic Multilingual Plane: 19 https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane 20 21 Make sure all the display driver and pin connections are correct by 22 editing the User_Setup.h file in the TFT_eSPI library folder. 23 24 ######################################################################### 25 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 26 ######################################################################### 27 */ 28 29 // Font files are stored in Flash FS 30 #include <FS.h> 31 #include <LittleFS.h> 32 #define FlashFS LittleFS 33 34 // Graphics and font library 35 #include <TFT_eSPI.h> 36 #include <SPI.h> 37 38 TFT_eSPI tft = TFT_eSPI(); // Invoke library 39 40 // ------------------------------------------------------------------------- 41 // Setup 42 // ------------------------------------------------------------------------- 43 void setup(void) { 44 Serial.begin(115200); // Used for messages 45 46 tft.init(); 47 tft.setRotation(1); 48 49 if (!LittleFS.begin()) { 50 Serial.println("Flash FS initialisation failed!"); 51 while (1) yield(); // Stay here twiddling thumbs waiting 52 } 53 Serial.println("\n\Flash FS available!"); 54 55 listFiles(); // Lists the files so you can see what is in the SPIFFS 56 57 } 58 59 // ------------------------------------------------------------------------- 60 // Main loop 61 // ------------------------------------------------------------------------- 62 void loop() { 63 // Wrap test at right and bottom of screen 64 tft.setTextWrap(true, true); 65 66 // Name of font file (library adds leading / and .vlw) 67 String fileName = "Final-Frontier-28"; 68 69 // Font and background colour, background colour is used for anti-alias blending 70 tft.setTextColor(TFT_WHITE, TFT_BLACK); 71 72 // Load the font 73 tft.loadFont(fileName, LittleFS); 74 75 // Display all characters of the font 76 tft.showFont(2000); 77 78 // Set "cursor" at top left corner of display (0,0) 79 // (cursor will move to next line automatically during printing with 'tft.println' 80 // or stay on the line is there is room for the text with tft.print) 81 tft.setCursor(0, 0); 82 83 // Set the font colour to be white with a black background, set text size multiplier to 1 84 tft.setTextColor(TFT_WHITE, TFT_BLACK); 85 86 // We can now plot text on screen using the "print" class 87 tft.println("Hello World!"); 88 89 // Set the font colour to be yellow 90 tft.setTextColor(TFT_YELLOW, TFT_BLACK); 91 tft.println(1234.56); 92 93 // Set the font colour to be red 94 tft.setTextColor(TFT_RED, TFT_BLACK); 95 tft.println((uint32_t)3735928559, HEX); // Should print DEADBEEF 96 97 // Set the font colour to be green with black background 98 tft.setTextColor(TFT_GREEN, TFT_BLACK); 99 tft.println("Anti-aliased font!"); 100 tft.println(""); 101 102 // Test some print formatting functions 103 float fnumber = 123.45; 104 105 // Set the font colour to be blue 106 tft.setTextColor(TFT_BLUE, TFT_BLACK); 107 tft.print("Float = "); tft.println(fnumber); // Print floating point number 108 tft.print("Binary = "); tft.println((int)fnumber, BIN); // Print as integer value in binary 109 tft.print("Hexadecimal = "); tft.println((int)fnumber, HEX); // Print as integer number in Hexadecimal 110 111 // Unload the font to recover used RAM 112 tft.unloadFont(); 113 114 delay(10000); 115 } 116 117 118 // ------------------------------------------------------------------------- 119 // List files in ESP8266 or ESP32 SPIFFS memory 120 // ------------------------------------------------------------------------- 121 void listFiles(void) { 122 Serial.println(); 123 Serial.println("Flash FS files found:"); 124 125 fs::Dir dir = LittleFS.openDir("/"); // Root directory 126 String line = "====================================="; 127 128 Serial.println(line); 129 Serial.println(" File name Size"); 130 Serial.println(line); 131 132 while (dir.next()) { 133 String fileName = dir.fileName(); 134 Serial.print(fileName); 135 int spaces = 25 - fileName.length(); // Tabulate nicely 136 if (spaces < 0) spaces = 1; 137 while (spaces--) Serial.print(" "); 138 fs::File f = dir.openFile("r"); 139 Serial.print(f.size()); Serial.println(" bytes"); 140 yield(); 141 } 142 143 Serial.println(line); 144 145 Serial.println(); 146 delay(1000); 147 } 148 149 // -------------------------------------------------------------------------