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 |
Local_Custom_Fonts.ino (4380B)
1 /* 2 Example for TFT_eSPI library 3 4 This example shows the use of a Adafruit_GFX custom font with a 5 character code range of 32 - 255, this means accented characters 6 (amongst others) are available. 7 8 The custom font file is attached to this sketch as a header file. The 9 font data has been created following the instructions here: 10 https://www.youtube.com/watch?v=L8MmTISmwZ8 11 12 Note that online converters for Adafruit_GFX compatible fonts are 13 available but these typically only use characters in the range 32-127, 14 and thus do not include the accented characters. These online converters 15 can however still be used with this sketch but the example characters 16 used must be changed. 17 18 The Arduino IDE uses UTF8 encoding for these characters. The TFT_eSPI 19 library also expects characters in the range 128 to 255 to be UTF-8 20 encoded. See link here for details: 21 22 https://playground.arduino.cc/Code/UTF-8 23 24 To summarise, UTF-8 characters are encoded as more than 1 byte so care must 25 be taken: 26 27 char c = 'µ'; // Wrong 28 char bad[4] = "5µA"; // Wrong 29 char good[] = "5µA"; // Good 30 String okay = "5µA"; // Good 31 32 Created by Bodmer 08/02/19 33 34 Make sure LOAD_GFXFF is defined in the used User_Setup file 35 within the library folder. 36 37 ######################################################################### 38 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 39 ###### TO SELECT YOUR DISPLAY TYPE, PINS USED AND ENABLE FONTS ###### 40 ######################################################################### 41 */ 42 43 #define TEST_TEXT "ßäöü ñâàå" // Text that will be printed on screen in the font 44 //#define TEST_TEXT "Hello" // Text that will be printed on screen in the font 45 46 #include "SPI.h" 47 #include "TFT_eSPI.h" 48 49 // The custom font file attached to this sketch must be included 50 #include "MyFont.h" 51 52 // Stock font and GFXFF reference handle 53 #define GFXFF 1 54 55 // Easily remembered name for the font 56 #define MYFONT32 &myFont32pt8b 57 58 // Use hardware SPI 59 TFT_eSPI tft = TFT_eSPI(); 60 61 void setup(void) { 62 63 Serial.begin(250000); 64 65 tft.begin(); 66 67 tft.setRotation(1); 68 69 } 70 71 void loop() { 72 73 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 74 // Show custom fonts 75 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 76 77 // Where font sizes increase the screen is not cleared as the larger fonts overwrite 78 // the smaller one with the background colour. 79 80 // We can set the text datum to be Top, Middle, Bottom vertically and Left, Centre 81 // and Right horizontally. These are the text datums that can be used: 82 // TL_DATUM = Top left (default) 83 // TC_DATUM = Top centre 84 // TR_DATUM = Top right 85 // ML_DATUM = Middle left 86 // MC_DATUM = Middle centre <<< This is used below 87 // MR_DATUM = Middle right 88 // BL_DATUM = Bottom left 89 // BC_DATUM = Bottom centre 90 // BR_DATUM = Bottom right 91 // L_BASELINE = Left character baseline (Line the 'A' character would sit on) 92 // C_BASELINE = Centre character baseline 93 // R_BASELINE = Right character baseline 94 95 //Serial.println(); 96 97 // Set text datum to middle centre (MC_DATUM) 98 tft.setTextDatum(MC_DATUM); 99 100 // Set text colour to white with black background 101 // Unlike the stock Adafruit_GFX library, the TFT_eSPI library DOES optionally draw 102 // the background colour for the custom and Free Fonts when using drawString() 103 tft.setTextColor(TFT_WHITE, TFT_BLACK); // White characters on black background 104 //tft.setTextColor(TFT_WHITE); // or white characters, no background 105 106 tft.fillScreen(TFT_BLUE); // Clear screen 107 tft.setFreeFont(MYFONT32); // Select the font 108 tft.drawString("MyFont 32", 160, 60, GFXFF); // Print the name of the font 109 tft.setFreeFont(MYFONT32); // Select the font 110 tft.drawString(TEST_TEXT, 160, 140, GFXFF); // Print the test text in the custom font 111 delay(2000); 112 113 // Setting textDatum does nothing when using tft.print 114 tft.fillScreen(TFT_BLUE); // Clear screen 115 tft.setCursor(0,60); // To be compatible with Adafruit_GFX the cursor datum is always bottom left 116 tft.print("âäàå"); // Using tft.print means text background is NEVER rendered 117 delay(2000); 118 119 // Reset text padding to zero (default) 120 tft.setTextPadding(0); 121 }