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 |
Unicode_test.ino (4204B)
1 // Created by Bodmer 24th Jan 2017 2 3 // The latest Arduino IDE versions support UTF-8 encoding of Unicode characters 4 // within sketches: 5 // https://playground.arduino.cc/Code/UTF-8 6 7 /* 8 The library expects strings to be in UTF-8 encoded format: 9 https://www.fileformat.info/info/unicode/utf8.htm 10 11 Creating varaibles needs to be done with care when using character arrays: 12 char c = 'µ'; // Wrong 13 char bad[4] = "5µA"; // Wrong 14 char good[] = "5µA"; // Good 15 String okay = "5µA"; // Good 16 17 This is because UTF-8 characters outside the basic Latin set occupy more than 18 1 byte per character! A 16 bit Unicode character occupies 3 bytes! 19 20 */ 21 22 // The fonts are stored in arrays within the sketch tabs. 23 24 // A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI 25 // https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font 26 27 #include "Final_Frontier_28.h" 28 #include "Latin_Hiragana_24.h" 29 #include "Unicode_Test_72.h" 30 31 //==================================================================================== 32 // Libraries 33 //==================================================================================== 34 35 #include <TFT_eSPI.h> // Hardware-specific library 36 37 TFT_eSPI tft = TFT_eSPI(); // Invoke custom library 38 39 uint16_t bg = TFT_BLACK; 40 uint16_t fg = TFT_WHITE; 41 42 43 //==================================================================================== 44 // Setup 45 //==================================================================================== 46 void setup() 47 { 48 Serial.begin(115200); // Used for messages and the C array generator 49 50 Serial.println("Font test!"); 51 52 tft.begin(); 53 tft.setRotation(0); // portrait 54 55 fg = TFT_WHITE; 56 bg = TFT_BLACK; 57 } 58 59 //==================================================================================== 60 // Loop 61 //==================================================================================== 62 void loop() 63 { 64 tft.setTextColor(fg, bg); 65 66 //---------------------------------------------------------------------------- 67 // Anti-aliased font test 68 69 String test1 = "Hello World"; 70 71 // Load a smooth font from SPIFFS 72 tft.loadFont(Final_Frontier_28); 73 74 tft.setRotation(0); 75 76 // Show all characters on screen with 2 second (2000ms) delay between screens 77 tft.showFont(2000); // Note: This function moves the cursor position! 78 79 tft.fillScreen(bg); 80 tft.setCursor(0,0); 81 82 tft.println(test1); 83 84 // Remove font parameters from memory to recover RAM 85 tft.unloadFont(); 86 87 delay(2000); 88 89 //---------------------------------------------------------------------------- 90 // We can have any random mix of characters in the font 91 92 String test2 = "仝倀"; // Unicodes 0x4EDD, 0x5000 93 94 tft.loadFont(Unicode_Test_72); 95 96 tft.setRotation(1); 97 98 // Show all characters on screen with 2 second (2000ms) delay between screens 99 tft.showFont(2000); // Note: This function moves the cursor position! 100 101 tft.fillScreen(bg); 102 tft.setCursor(0,0); 103 104 tft.setTextColor(TFT_CYAN, bg); 105 tft.println(test2); 106 107 tft.setTextColor(TFT_YELLOW, bg); 108 tft.println("12:00pm"); 109 110 tft.setTextColor(TFT_MAGENTA, bg); 111 tft.println("1000Ω"); 112 113 // Remove font parameters from memory to recover RAM 114 tft.unloadFont(); 115 116 delay(2000); 117 118 //---------------------------------------------------------------------------- 119 // Latin and Hiragana font mix 120 121 String test3 = "こんにちは"; 122 123 tft.loadFont(Latin_Hiragana_24); 124 125 tft.setRotation(0); 126 127 // Show all characters on screen with 2 second (2000ms) delay between screens 128 tft.showFont(2000); // Note: This function moves the cursor position! 129 130 tft.fillScreen(bg); 131 tft.setTextColor(TFT_GREEN, bg); 132 tft.setCursor(0,0); 133 134 tft.println("Konnichiwa"); 135 tft.println(test3); 136 tft.println(); 137 tft.println("Sayonara"); 138 tft.println("さようなら"); // Sayonara 139 140 // Remove font parameters from memory to recover RAM 141 tft.unloadFont(); 142 143 delay(2000); 144 // 145 //---------------------------------------------------------------------------- 146 } 147 //====================================================================================