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 (4504B)

      1 //  Created by Bodmer 24th Jan 2017 - Tested in Arduino IDE 1.8.5 esp8266 Core 2.4.0
      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 variables 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   // Flash filing system
     23   #include <FS.h>
     24   #include <LittleFS.h>
     25 
     26 
     27 //====================================================================================
     28 //                                  Libraries
     29 //====================================================================================
     30 // Call up the FLASH filing system this is part of the ESP Core
     31 
     32 #include <TFT_eSPI.h>      // Hardware-specific library
     33 
     34 TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
     35 
     36 uint16_t bg = TFT_BLACK;
     37 uint16_t fg = TFT_WHITE;
     38 
     39 
     40 //====================================================================================
     41 //                                    Setup
     42 //====================================================================================
     43 void setup()
     44 {
     45   Serial.begin(115200); // Used for messages and the C array generator
     46 
     47   Serial.println("NodeMCU vlw font test!");
     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("\nInitialisation done.");
     54 
     55   listFiles(); // Lists the files so you can see what is in the Flash FS
     56 
     57   tft.begin();
     58   tft.setRotation(0);  // portrait
     59 
     60   fg = TFT_WHITE;
     61   bg = TFT_BLACK;
     62 }
     63 
     64 //====================================================================================
     65 //                                    Loop
     66 //====================================================================================
     67 void loop()
     68 {
     69   tft.setTextColor(fg, bg);
     70 
     71   //----------------------------------------------------------------------------
     72   // Anti-aliased font test
     73 
     74   String test1 = "Hello World";
     75 
     76   // Load a smooth font from Flash FS
     77   tft.loadFont("Final-Frontier-28", LittleFS);
     78 
     79   tft.setRotation(0);
     80 
     81   // Show all characters on screen with 2 second (2000ms) delay between screens
     82   tft.showFont(2000); // Note: This function moves the cursor position!
     83 
     84   tft.fillScreen(bg);
     85   tft.setCursor(0,0);
     86 
     87   tft.println(test1);
     88 
     89   // Remove font parameters from memory to recover RAM
     90   tft.unloadFont();
     91 
     92   delay(2000);
     93 
     94   //----------------------------------------------------------------------------
     95   // We can have any random mix of characters in the font
     96 
     97   String test2 = "仝倀"; // Unicodes 0x4EDD, 0x5000
     98 
     99   tft.loadFont("Unicode-Test-72", LittleFS);
    100 
    101   tft.setRotation(1);
    102 
    103   // Show all characters on screen with 2 second (2000ms) delay between screens
    104   tft.showFont(2000); // Note: This function moves the cursor position!
    105 
    106   tft.fillScreen(bg);
    107   tft.setCursor(0,0);
    108 uint32_t dt = millis();
    109   tft.setTextColor(TFT_CYAN, bg);
    110   tft.println(test2);
    111 
    112   tft.setTextColor(TFT_YELLOW, bg);
    113   tft.println("12:00pm");
    114 
    115   tft.setTextColor(TFT_MAGENTA, bg);
    116   tft.println("1000Ω");
    117 Serial.println(millis()-dt);
    118   // Remove font parameters from memory to recover RAM
    119   tft.unloadFont();
    120 
    121   delay(2000);
    122 
    123   //----------------------------------------------------------------------------
    124   // Latin and Hiragana font mix
    125 
    126   String test3 = "こんにちは";
    127     
    128   tft.loadFont("Latin-Hiragana-24",LittleFS);
    129 
    130   tft.setRotation(0);
    131 dt = millis();
    132   // Show all characters on screen with 2 second (2000ms) delay between screens
    133   tft.showFont(2000); // Note: This function moves the cursor position!
    134 Serial.println(millis()-dt);
    135   tft.fillScreen(bg);
    136   tft.setTextColor(TFT_GREEN, bg);
    137   tft.setCursor(0,0);
    138 dt = millis();
    139   tft.println("Konnichiwa");
    140   tft.println(test3);
    141   tft.println();
    142   tft.println("Sayonara");
    143   tft.println("さようなら"); // Sayonara
    144 Serial.println(millis()-dt);
    145   // Remove font parameters from memory to recover RAM
    146   tft.unloadFont();
    147 
    148   delay(2000);
    149   //
    150   //----------------------------------------------------------------------------
    151 }
    152 //====================================================================================