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_Custom_Fonts.ino (5805B)
1 /* 2 Example for TFT_eSPI library 3 4 Created by Bodmer 11/03/17 5 6 Make sure LOAD_GFXFF is defined in the used User_Setup file 7 within the library folder. 8 9 --------------------------- NOTE ---------------------------------------- 10 The free font encoding format does not lend itself easily to plotting 11 the background without flicker. For values that changes on screen it is 12 better to use Fonts 1- 8 which are encoded specifically for rapid 13 drawing with background. 14 ------------------------------------------------------------------------- 15 16 ######################################################################### 17 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 18 ###### TO SELECT YOUR DISPLAY TYPE, PINS USED AND ENABLE FONTS ###### 19 ######################################################################### 20 */ 21 22 // Note the the tilda symbol ~ does not exist in some fonts at the moment 23 #define TEXT "abc MWy 123 |" // Text that will be printed on screen in any font 24 25 #include "SPI.h" 26 #include "TFT_eSPI.h" 27 28 // Stock font and GFXFF reference handle 29 #define GFXFF 1 30 #define FF18 &FreeSans12pt7b 31 32 // Custom are fonts added to library "TFT_eSPI\Fonts\Custom" folder 33 // a #include must also be added to the "User_Custom_Fonts.h" file 34 // in the "TFT_eSPI\User_Setups" folder. See example entries. 35 #define CF_OL24 &Orbitron_Light_24 36 #define CF_OL32 &Orbitron_Light_32 37 #define CF_RT24 &Roboto_Thin_24 38 #define CF_S24 &Satisfy_24 39 #define CF_Y32 &Yellowtail_32 40 41 42 // Use hardware SPI 43 TFT_eSPI tft = TFT_eSPI(); 44 45 void setup(void) { 46 47 Serial.begin(250000); 48 49 tft.begin(); 50 51 tft.setRotation(1); 52 53 } 54 55 void loop() { 56 57 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 58 // Show custom fonts 59 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 60 61 // Where font sizes increase the screen is not cleared as the larger fonts overwrite 62 // the smaller one with the background colour. 63 64 // We can set the text datum to be Top, Middle, Bottom vertically and Left, Centre 65 // and Right horizontally. These are the text datums that can be used: 66 // TL_DATUM = Top left (default) 67 // TC_DATUM = Top centre 68 // TR_DATUM = Top right 69 // ML_DATUM = Middle left 70 // MC_DATUM = Middle centre <<< This is used below 71 // MR_DATUM = Middle right 72 // BL_DATUM = Bottom left 73 // BC_DATUM = Bottom centre 74 // BR_DATUM = Bottom right 75 // L_BASELINE = Left character baseline (Line the 'A' character would sit on) 76 // C_BASELINE = Centre character baseline 77 // R_BASELINE = Right character baseline 78 79 //Serial.println(); 80 81 // Set text datum to middle centre (MC_DATUM) 82 tft.setTextDatum(MC_DATUM); 83 84 // Set text colour to white with black background 85 // Unlike the stock Adafruit_GFX library, the TFT_eSPI library DOES draw the background 86 // for the custom and Free Fonts 87 tft.setTextColor(TFT_WHITE, TFT_BLACK); 88 89 tft.fillScreen(TFT_MAGENTA); // Clear screen 90 tft.setFreeFont(FF18); // Select the font 91 tft.drawString("Yellowtail 32", 160, 60, GFXFF);// Print the string name of the font 92 tft.setFreeFont(CF_Y32); // Select the font 93 tft.drawString(TEXT, 160, 120, GFXFF);// Print the string name of the font 94 delay(2000); 95 96 tft.fillScreen(TFT_BLUE); // Clear screen 97 tft.setFreeFont(FF18); // Select the font 98 tft.drawString("Satisfy 24", 160, 60, GFXFF);// Print the string name of the font 99 tft.setFreeFont(CF_S24); // Select the font 100 tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font 101 delay(2000); 102 103 tft.fillScreen(TFT_RED); // Clear screen 104 tft.setFreeFont(FF18); // Select the font 105 tft.drawString("Roboto 24", 160, 60, GFXFF);// Print the string name of the font 106 tft.setFreeFont(CF_RT24); // Select the font 107 tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font 108 delay(2000); 109 110 tft.fillScreen(TFT_DARKGREY); // Clear screen 111 tft.setFreeFont(FF18); // Select the font 112 tft.drawString("Orbitron 24", 160, 60, GFXFF);// Print the string name of the font 113 tft.setFreeFont(CF_OL24); // Select the font 114 tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font 115 delay(2000); 116 117 // Here we do not clear the screen and rely on the new text over-writing the old 118 tft.setFreeFont(FF18); // Select the font 119 tft.drawString("Orbitron 32", 160, 60, GFXFF);// Print the string name of the font 120 tft.setFreeFont(CF_OL32); // Select the font 121 tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font 122 delay(2000); 123 124 // Here we use text background padding to over-write the old text 125 tft.fillScreen(TFT_YELLOW); // Clear screen 126 tft.setTextColor(TFT_WHITE, TFT_BLACK); 127 128 // Here we use text background padding to over-write the old text 129 tft.setTextPadding(tft.width() - 20); // Blanked area will be width of screen minus 20 pixels 130 tft.setFreeFont(FF18); // Select the font 131 tft.drawString("Orbitron 32 with padding", 160, 60, GFXFF);// Print the string name of the font 132 tft.setFreeFont(CF_OL32); // Select the font 133 tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font 134 delay(2000); 135 136 // Use 80 pixel wide padding so old numbers over-write old ones 137 // One of the problrms with proportionally spaced numbers is that they jiggle position 138 tft.setTextPadding(80); 139 tft.setTextDatum(MC_DATUM); 140 tft.setFreeFont(CF_OL32); 141 for( int i = 100; i > 0; i--) 142 { 143 tft.drawNumber( i, 160, 200); 144 delay(500); 145 } 146 147 // Reset text padding to zero (default) 148 tft.setTextPadding(0); 149 } 150