acidportal

- 😈 Worlds smallest Evil Portal on a LilyGo T-QT
git clone git://git.acid.vegas/acidportal.git
Log | Files | Refs | Archive | README | LICENSE

Unicode_test.ino (4275B)

      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 //====================================================================================
     23 //                                  Libraries
     24 //====================================================================================
     25 // Call up the SPIFFS FLASH filing system this is part of the ESP Core
     26 
     27 #include <TFT_eSPI.h>      // Hardware-specific library
     28 
     29 TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
     30 
     31 uint16_t bg = TFT_BLACK;
     32 uint16_t fg = TFT_WHITE;
     33 
     34 
     35 //====================================================================================
     36 //                                    Setup
     37 //====================================================================================
     38 void setup()
     39 {
     40   Serial.begin(115200); // Used for messages and the C array generator
     41 
     42   Serial.println("NodeMCU vlw font test!");
     43 
     44   if (!SPIFFS.begin()) {
     45     Serial.println("SPIFFS initialisation failed!");
     46     while (1) yield(); // Stay here twiddling thumbs waiting
     47   }
     48   Serial.println("\r\nInitialisation done.");
     49 
     50   listFiles(); // Lists the files so you can see what is in the SPIFFS
     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 //====================================================================================
    148