Commit c689b421 authored by Bodmer's avatar Bodmer

Add FLASH based anti-aliased fonts

Processors (such as STM32) that are not supported by a SPIFFS library can now use anti-aliased (smooth) fonts stored in FLASH (program) memory.
parent d2270c36
......@@ -8,16 +8,30 @@
/***************************************************************************************
** Function name: loadFont
** Description: loads parameters from a new font vlw file
** Description: loads parameters from a font vlw array in memory
*************************************************************************************x*/
void TFT_eSPI::loadFont(const uint8_t array[])
{
if(array == nullptr) return;
fontPtr = (uint8_t*) array;
loadFont("", false);
}
#if defined (ESP32) || defined (ESP8266)
/***************************************************************************************
** Function name: loadFont
** Description: loads parameters from a font vlw file
*************************************************************************************x*/
void TFT_eSPI::loadFont(String fontName, fs::FS &ffs)
{
fontFS = ffs;
loadFont(fontName, false);
}
#endif
/***************************************************************************************
** Function name: loadFont
** Description: loads parameters from a new font vlw file
** Description: loads parameters from a font vlw file
*************************************************************************************x*/
void TFT_eSPI::loadFont(String fontName, bool flash)
{
......@@ -80,11 +94,13 @@ void TFT_eSPI::loadFont(String fontName, bool flash)
*/
spiffs = flash;
if (fontLoaded) unloadFont();
if(spiffs) fontFS = SPIFFS;
#if defined (ESP32) || defined (ESP8266)
spiffs = flash; // true if font is in SPIFFS
unloadFont();
if(spiffs) fontFS = SPIFFS;
// Avoid a crash on the ESP32 if the file does not exist
if (fontFS.exists("/" + fontName + ".vlw") == false) {
......@@ -97,6 +113,9 @@ void TFT_eSPI::loadFont(String fontName, bool flash)
if(!fontFile) return;
fontFile.seek(0, fs::SeekSet);
#endif
gFont.gArray = (const uint8_t*)fontPtr;
gFont.gCount = (uint16_t)readInt32(); // glyph count in file
readInt32(); // vlw encoder version - discard
......@@ -114,9 +133,7 @@ void TFT_eSPI::loadFont(String fontName, bool flash)
fontLoaded = true;
// Fetch the metrics for each glyph
loadMetrics(gFont.gCount);
//fontFile.close();
loadMetrics();
}
......@@ -125,32 +142,32 @@ void TFT_eSPI::loadFont(String fontName, bool flash)
** Description: Get the metrics for each glyph and store in RAM
*************************************************************************************x*/
//#define SHOW_ASCENT_DESCENT
void TFT_eSPI::loadMetrics(uint16_t gCount)
void TFT_eSPI::loadMetrics(void)
{
uint32_t headerPtr = 24;
uint32_t bitmapPtr = 24 + gCount * 28;
uint32_t bitmapPtr = 24 + gFont.gCount * 28;
#if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT)
if ( psramFound() )
{
gUnicode = (uint16_t*)ps_malloc( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF)
gHeight = (uint8_t*)ps_malloc( gCount ); // Height of glyph
gWidth = (uint8_t*)ps_malloc( gCount ); // Width of glyph
gxAdvance = (uint8_t*)ps_malloc( gCount ); // xAdvance - to move x cursor
gdY = (int16_t*)ps_malloc( gCount * 2); // offset from bitmap top edge from lowest point in any character
gdX = (int8_t*)ps_malloc( gCount ); // offset for bitmap left edge relative to cursor X
gBitmap = (uint32_t*)ps_malloc( gCount * 4); // seek pointer to glyph bitmap in the file
gUnicode = (uint16_t*)ps_malloc( gFont.gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF)
gHeight = (uint8_t*)ps_malloc( gFont.gCount ); // Height of glyph
gWidth = (uint8_t*)ps_malloc( gFont.gCount ); // Width of glyph
gxAdvance = (uint8_t*)ps_malloc( gFont.gCount ); // xAdvance - to move x cursor
gdY = (int16_t*)ps_malloc( gFont.gCount * 2); // offset from bitmap top edge from lowest point in any character
gdX = (int8_t*)ps_malloc( gFont.gCount ); // offset for bitmap left edge relative to cursor X
gBitmap = (uint32_t*)ps_malloc( gFont.gCount * 4); // seek pointer to glyph bitmap in the file
}
else
#endif
{
gUnicode = (uint16_t*)malloc( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF)
gHeight = (uint8_t*)malloc( gCount ); // Height of glyph
gWidth = (uint8_t*)malloc( gCount ); // Width of glyph
gxAdvance = (uint8_t*)malloc( gCount ); // xAdvance - to move x cursor
gdY = (int16_t*)malloc( gCount * 2); // offset from bitmap top edge from lowest point in any character
gdX = (int8_t*)malloc( gCount ); // offset for bitmap left edge relative to cursor X
gBitmap = (uint32_t*)malloc( gCount * 4); // seek pointer to glyph bitmap in the file
gUnicode = (uint16_t*)malloc( gFont.gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF)
gHeight = (uint8_t*)malloc( gFont.gCount ); // Height of glyph
gWidth = (uint8_t*)malloc( gFont.gCount ); // Width of glyph
gxAdvance = (uint8_t*)malloc( gFont.gCount ); // xAdvance - to move x cursor
gdY = (int16_t*)malloc( gFont.gCount * 2); // offset from bitmap top edge from lowest point in any character
gdX = (int8_t*)malloc( gFont.gCount ); // offset for bitmap left edge relative to cursor X
gBitmap = (uint32_t*)malloc( gFont.gCount * 4); // seek pointer to glyph bitmap in the file
}
#ifdef SHOW_ASCENT_DESCENT
......@@ -158,9 +175,13 @@ void TFT_eSPI::loadMetrics(uint16_t gCount)
Serial.print("descent = "); Serial.println(gFont.descent);
#endif
uint16_t gNum = 0;
#if defined (ESP32) || defined (ESP8266)
fontFile.seek(headerPtr, fs::SeekSet);
while (gNum < gCount)
#endif
uint16_t gNum = 0;
while (gNum < gFont.gCount)
{
gUnicode[gNum] = (uint16_t)readInt32(); // Unicode code point value
gHeight[gNum] = (uint8_t)readInt32(); // Height of glyph
......@@ -207,7 +228,7 @@ void TFT_eSPI::loadMetrics(uint16_t gCount)
gBitmap[gNum] = bitmapPtr;
headerPtr += 28;
//headerPtr += 28;
bitmapPtr += gWidth[gNum] * gHeight[gNum];
......@@ -269,7 +290,12 @@ void TFT_eSPI::unloadFont( void )
gBitmap = NULL;
}
gFont.gArray = nullptr;
#if defined (ESP32) || defined (ESP8266)
if(fontFile) fontFile.close();
#endif
fontLoaded = false;
}
......@@ -281,10 +307,18 @@ void TFT_eSPI::unloadFont( void )
uint32_t TFT_eSPI::readInt32(void)
{
uint32_t val = 0;
#if defined (ESP32) || defined (ESP8266)
val |= fontFile.read() << 24;
val |= fontFile.read() << 16;
val |= fontFile.read() << 8;
val |= fontFile.read();
#else
val |= (*fontPtr++) << 24;
val |= (*fontPtr++) << 16;
val |= (*fontPtr++) << 8;
val |= (*fontPtr++);
#endif
return val;
}
......@@ -346,11 +380,14 @@ void TFT_eSPI::drawGlyph(uint16_t code)
if (textwrapY && ((cursor_y + gFont.yAdvance) >= _height)) cursor_y = 0;
if (cursor_x == 0) cursor_x -= gdX[gNum];
#if defined (ESP32) || defined (ESP8266)
fontFile.seek(gBitmap[gNum], fs::SeekSet); // This is taking >30ms for a significant position shift
uint8_t pbuffer[gWidth[gNum]];
#else
const uint8_t* gPtr = (const uint8_t*) gFont.gArray;
#endif
int16_t xs = 0;
int16_t xs = 0;
uint32_t dl = 0;
int16_t cy = cursor_y + gFont.maxAscent - gdY[gNum];
......@@ -360,6 +397,7 @@ void TFT_eSPI::drawGlyph(uint16_t code)
for (int y = 0; y < gHeight[gNum]; y++)
{
#if defined (ESP32) || defined (ESP8266)
if (spiffs)
{
fontFile.read(pbuffer, gWidth[gNum]);
......@@ -372,10 +410,14 @@ void TFT_eSPI::drawGlyph(uint16_t code)
startWrite(); // Re-start SPI for TFT transaction
//Serial.println("Not SPIFFS");
}
#endif
for (int x = 0; x < gWidth[gNum]; x++)
{
uint8_t pixel = pbuffer[x]; //<//
#if defined (ESP32) || defined (ESP8266)
uint8_t pixel = pbuffer[x];
#else
uint8_t pixel = gPtr[gBitmap[gNum] + x + gWidth[gNum] * y];
#endif
if (pixel)
{
if (pixel != 0xFF)
......@@ -421,11 +463,13 @@ void TFT_eSPI::showFont(uint32_t td)
{
if(!fontLoaded) return;
#if defined (ESP32) || defined (ESP8266)
if(!fontFile)
{
fontLoaded = false;
return;
}
#endif
int16_t cursorX = width(); // Force start of new page to initialise cursor
int16_t cursorY = height();// for the first character
......
......@@ -4,7 +4,10 @@
public:
// These are for the new antialiased fonts
void loadFont(const uint8_t array[]);
#if defined (ESP32) || defined (ESP8266)
void loadFont(String fontName, fs::FS &ffs);
#endif
void loadFont(String fontName, bool flash = true);
void unloadFont( void );
bool getUnicodeIndex(uint16_t unicode, uint16_t *index);
......@@ -16,13 +19,14 @@
// This is for the whole font
typedef struct
{
uint16_t gCount; // Total number of characters
uint16_t yAdvance; // Line advance
uint16_t spaceWidth; // Width of a space character
int16_t ascent; // Height of top of 'd' above baseline, other characters may be taller
int16_t descent; // Offset to bottom of 'p', other characters may have a larger descent
uint16_t maxAscent; // Maximum ascent found in font
uint16_t maxDescent; // Maximum descent found in font
const uint8_t* gArray = nullptr; //array start pointer
uint16_t gCount; // Total number of characters
uint16_t yAdvance; // Line advance
uint16_t spaceWidth; // Width of a space character
int16_t ascent; // Height of top of 'd' above baseline, other characters may be taller
int16_t descent; // Offset to bottom of 'p', other characters may have a larger descent
uint16_t maxAscent; // Maximum ascent found in font
uint16_t maxDescent; // Maximum descent found in font
} fontMetrics;
fontMetrics gFont = { 0, 0, 0, 0, 0, 0, 0 };
......@@ -37,12 +41,19 @@ fontMetrics gFont = { 0, 0, 0, 0, 0, 0, 0 };
uint32_t* gBitmap = NULL; //file pointer to greyscale bitmap
bool fontLoaded = false; // Flags when a anti-aliased font is loaded
#if defined (ESP32) || defined (ESP8266)
fs::File fontFile;
fs::FS &fontFS = SPIFFS;
bool spiffs = true;
#else
bool fontFile = true;
#endif
private:
void loadMetrics(uint16_t gCount);
void loadMetrics(void);
uint32_t readInt32(void);
fs::FS &fontFS = SPIFFS;
bool spiffs = true;
\ No newline at end of file
uint8_t* fontPtr = nullptr;
......@@ -2359,19 +2359,28 @@ void TFT_eSprite::drawGlyph(uint16_t code)
this->cursor_y = 0;
}
#if defined (ESP32) || defined (ESP8266)
this->fontFile.seek(this->gBitmap[gNum], fs::SeekSet); // This is slow for a significant position shift!
uint8_t pbuffer[this->gWidth[gNum]];
#else
const uint8_t* gPtr = (const uint8_t*) this->gFont.gArray;
#endif
int16_t xs = 0;
uint16_t dl = 0;
for (int32_t y = 0; y < this->gHeight[gNum]; y++)
{
#if defined (ESP32) || defined (ESP8266)
this->fontFile.read(pbuffer, this->gWidth[gNum]);
#endif
for (int32_t x = 0; x < this->gWidth[gNum]; x++)
{
#if defined (ESP32) || defined (ESP8266)
uint8_t pixel = pbuffer[x];
#else
uint8_t pixel = gPtr[gBitmap[gNum] + x + gWidth[gNum] * y];
#endif
if (pixel)
{
if (pixel != 0xFF)
......
......@@ -147,7 +147,7 @@
// Command is 16 bits
#define CMD_BITS 16
// ESP32 low level SPI writes for 8, 16 and 32 bit values
// ESP8266 low level SPI writes for 8, 16 and 32 bit values
// to avoid the function call overhead
#define TFT_WRITE_BITS(D, B) \
SPI1U1 = ((B-1) << SPILMOSI); \
......@@ -176,11 +176,11 @@
////////////////////////////////////////////////////////////////////////////////////////
#else
// Command is 8 bits
#define CMD_BITS (8-1)
#define CMD_BITS 8
#define tft_Write_8(C) \
SPI1U1 = (CMD_BITS << SPILMOSI) | (CMD_BITS << SPILMISO); \
SPI1W0 = (C)<<(CMD_BITS + 1 - 8); \
SPI1U1 = ((CMD_BITS-1) << SPILMOSI) | ((CMD_BITS-1) << SPILMISO); \
SPI1W0 = (C)<<(CMD_BITS - 8); \
SPI1CMD |= SPIBUSY; \
while(SPI1CMD & SPIBUSY) {;}
......
......@@ -16,7 +16,7 @@
#ifndef _TFT_eSPIH_
#define _TFT_eSPIH_
#define TFT_ESPI_VERSION "2.0.4"
#define TFT_ESPI_VERSION "2.1.0"
/***************************************************************************************
** Section 1: Load required header files
......
......@@ -15,8 +15,19 @@
//
// ##################################################################################
// Define STM32 to invoke optimised processor support (only for STM32)
//#define STM32
// Defining the STM32 board allows the library to optimise the performance
// for UNO compatible "MCUfriend" style shields
//#define NUCLEO_64_TFT
//#define NUCLEO_144_TFT
// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed)
//#define TFT_PARALLEL_8_BIT
// Display type - only define if RPi display
//#define RPI_DRIVER
//#define RPI_DISPLAY_TYPE // 20MHz maximum SPI
// Only define one driver, the other ones must be commented out
#define ILI9341_DRIVER
......
......@@ -59,6 +59,9 @@
//#include <User_Setups/Setup30_ILI9341_Parallel_STM32.h> // Setup for Nucleo board and parallel display
//#include <User_Setups/Setup31_ST7796_Parallel_STM32.h> // Setup for Nucleo board and parallel display
//#include <User_Setups/Setup32_ILI9341_STM32F103.h> // Setup for "Blue Pill"
//#include <User_Setups/Setup33_RPi_ILI9486_STM32.h> // Setup for Nucleo board
//#include <User_Setups/Setup36_RPi_touch_ILI9341.h> // Setup file configured for ESP32 and RPi TFT with touch
//#include <User_Setups/Setup43_ST7735.h> // Setup file configured for my ST7735S 80x160
......
// See SetupX_Template.h for all options available
#define RPI_ILI9486_DRIVER // 20MHz maximum SPI
#define RPI_DISPLAY_TYPE
#define ILI9486_DRIVER // 20MHz maximum SPI
// For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation
#define TFT_CS PIN_D2 // Chip select control pin D2
......
// See SetupX_Template.h for all options available
#define RPI_ILI9486_DRIVER // 20MHz maximum SPI
#define RPI_DISPLAY_TYPE
#define ILI9486_DRIVER // 20MHz maximum SPI
#define TFT_MISO 19
#define TFT_MOSI 23
......
......@@ -14,7 +14,7 @@
// ##################################################################################
// Display type - only define if RPi display
#define RPI_DRIVER
#define RPI_DISPLAY_TYPE
// Only define one driver
#define ST7796_DRIVER
......
......@@ -14,7 +14,7 @@
// ##################################################################################
// Display type - only define if RPi display
#define RPI_DRIVER
#define RPI_DISPLAY_TYPE
// Only define one driver
#define ST7796_DRIVER
......
......@@ -22,7 +22,7 @@
// MOSI and SCK do not need to be defined, connect:
// - Arduino SCK to TFT SCK
// - Arduino MOSI to TFT SDI(may be marked SDA or MOSI)
// Standard Arduino SPI pins are p(SCK=D13, MOSI=D11) this is port pins PA5 and PA7 on Nucleo-F767ZI
// Standard Arduino SPI pins are (SCK=D13, MOSI=D11) this is port pins PA5 and PA7 on Nucleo-F767ZI
// Can use Ardiuno pin references, arbitrary allocation, TFT_eSPI controls chip select
#define TFT_CS D5 // Chip select control pin to TFT CS
......
////////////////////////////////////////////////////
// Setup for Nucleo 64 or 144 and ILI9341 display //
///////////////////////////////////////////////////
////////////////////////////////////////////////////
// See SetupX_Template.h for all options available
......@@ -49,4 +49,4 @@
// At the moment SMOOTH fonts must be disabled for STM32 processors (due to lack of SPIFFS)
// Support for smooth fonts via SD cards is planned.
//#define SMOOTH_FONT
#define SMOOTH_FONT
///////////////////////////////////////////////////
// Setup for STM32 Nucleo and ILI9341 display //
///////////////////////////////////////////////////
// Last update by Bodmer: 28/11/19
// STM32 optimised functions are not yet compatible with STM32H743 processor.
// The STM32H743 does work with the slower generic processor drivers
//
// REMINDER - Nucleo-F743ZI and Nucleo-F743ZI2 have different pin port allocations
// and require appropriate selection in IDE. ^---- Note the extra 2 in part number!
// Define STM32 to invoke STM32 optimised driver (optimised fns only tested on STM32F767 so far)
// so you may need to comment this out
#define STM32
// Define the TFT display driver
#define RPI_DISPLAY_TYPE
#define ILI9486_DRIVER
// MOSI and SCK do not need to be defined, connect:
// - Arduino SCK to TFT SCK
// - Arduino MOSI to TFT SDI(may be marked SDA or MOSI)
// Standard Arduino SPI pins are(SCK=D13, MOSI=D11) this is port pins PA5 and PA7 on Nucleo-F767ZI
// Can use Ardiuno pin references, arbitrary allocation, TFT_eSPI controls chip select
#define TFT_CS D5 // Chip select control pin to TFT CS
#define TFT_DC D6 // Data Command control pin to TFT DC (may be labelled RS = Register Select)
#define TFT_RST D7 // Reset pin to TFT RST (or RESET)
// Alternatively, we can use STM32 port reference names PXnn
//#define TFT_CS PE11 // Nucleo-F767ZI equivalent of D5
//#define TFT_DC PE9 // Nucleo-F767ZI equivalent of D6
//#define TFT_RST PF13 // Nucleo-F767ZI equivalent of D7
//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to processor reset
// Use an Arduino pin for initial testing as connecting to processor reset
// may not work (pulse too short at power up?)
// Chip select for XPT2046 touch controller
//#define TOUCH_CS D4
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
// At the moment SMOOTH fonts must be disabled for STM32 processors (due to lack of SPIFFS)
// Support for smooth fonts via SD cards is planned.
//#define SMOOTH_FONT // Must be commented out for STM32
// Nucleo-F767ZI has a ~216MHZ CPU clock, this is divided by 4, 8, 16 etc
#define SPI_FREQUENCY 20000000 // 27MHz SPI clock
//#define SPI_FREQUENCY 55000000 // 55MHz is over-clocking ILI9341 but seems to work reliably!
//#define SPI_READ_FREQUENCY 15000000 // Reads need a slower SPI clock, probably ends up at 13.75MHz (CPU clock/16)
//#define SPI_TOUCH_FREQUENCY 2500000 // Must be very slow
// This has no effect, transactions for STM32 are automatically enabled
#define SUPPORT_TRANSACTIONS
// See SetupX_Template.h for all options available
#define RPI_DISPLAY_TYPE
#define ST7796_DRIVER // 20MHz maximum SPI
#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 15 // Chip select control pin
#define TFT_DC 2 // Data Command control pin
#define TFT_RST 4 // Reset pin (could connect to RST pin)
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
#define TOUCH_CS 22 // Chip select pin (T_CS) of touch screen
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
#define SPI_FREQUENCY 40000000
#define SPI_TOUCH_FREQUENCY 2500000
......@@ -8,19 +8,31 @@
// run without the need to make any more changes for a particular hardware setup!
// Note that some sketches are designed for a particular TFT pixel width/height
// ##################################################################################
//
// Section 1. Call up the right driver file and any options for it
//
// ##################################################################################
// Define STM32 to invoke optimised processor support (only for STM32)
//#define STM32
// Defining the STM32 board allows the library to optimise the performance
// for UNO compatible "MCUfriend" style shields
//#define NUCLEO_64_TFT
//#define NUCLEO_144_TFT
// Tell the library to use 8 bit parallel mode(otherwise SPI is assumed)
//#define TFT_PARALLEL_8_BIT
// Display type - only define if RPi display
//#define RPI_DISPLAY_TYPE // 20MHz maximum SPI
// Only define one driver, the other ones must be commented out
#define ILI9341_DRIVER
//#define ST7735_DRIVER // Define additional parameters below for this display
//#define ILI9163_DRIVER // Define additional parameters below for this display
//#define S6D02A1_DRIVER
//#define RPI_ILI9486_DRIVER // 20MHz maximum SPI
//#define HX8357D_DRIVER
//#define ILI9481_DRIVER
//#define ILI9486_DRIVER
......@@ -29,6 +41,7 @@
//#define ST7789_2_DRIVER // Minimal configuration option, define additional parameters below for this display
//#define R61581_DRIVER
//#define RM68140_DRIVER
//#define ST7796_DRIVER
// Some displays support SPI reads via the MISO pin, other displays have a single
// bi-directional SDA pin and the library will try to read this via the MOSI line.
......
/*
This sketch is the same as the Font_Demo_1 example, except the fonts in this
example are in a FLASH (program memory) array. This means that processors
such as the STM32 series that are not supported by a SPIFFS library can use
smooth (anti-aliased) fonts.
*/
/*
There are four different methods of plotting anti-aliased fonts to the screen.
This sketch uses method 1, using tft.print() and tft.println() calls.
In some cases the sketch shows what can go wrong too, so read the comments!
The font is rendered WITHOUT a background, but a background colour needs to be
set so the anti-aliasing of the character is performed correctly. This is because
characters are drawn one by one.
This method is good for static text that does not change often because changing
values may flicker. The text appears at the tft cursor coordinates.
It is also possible to "print" text directly into a created sprite, for example using
spr.println("Hello"); and then push the sprite to the screen. That method is not
demonstrated in this sketch.
*/
// A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI
// https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font
// This sketch uses font files created from the Noto family of fonts:
// https://www.google.com/get/noto/
#include "NotoSansBold15.h"
#include "NotoSansBold36.h"
// The font names are arrays references, thus must NOT be in quotes ""
#define AA_FONT_SMALL NotoSansBold15
#define AA_FONT_LARGE NotoSansBold36
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
void setup(void) {
Serial.begin(250000);
tft.begin();
tft.setRotation(0);
}
void loop() {
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set the font colour AND the background colour
// so the anti-aliasing works
tft.setCursor(0, 0); // Set cursor at top left of screen
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Small font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Serial.println("Loading font");
tft.loadFont(AA_FONT_SMALL); // Must load the font first
tft.println("Small 15pt font"); // println moves cursor down for a new line
tft.println(); // New line
tft.print("ABC"); // print leaves cursor at end of line
tft.setTextColor(TFT_CYAN, TFT_BLACK);
tft.println("1234"); // Added to line after ABC
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
// print stream formatting can be used,see:
// https://www.arduino.cc/en/Serial/Print
int ivalue = 1234;
tft.println(ivalue); // print as an ASCII-encoded decimal
tft.println(ivalue, DEC); // print as an ASCII-encoded decimal
tft.println(ivalue, HEX); // print as an ASCII-encoded hexadecimal
tft.println(ivalue, OCT); // print as an ASCII-encoded octal
tft.println(ivalue, BIN); // print as an ASCII-encoded binary
tft.println(); // New line
tft.setTextColor(TFT_MAGENTA, TFT_BLACK);
float fvalue = 1.23456;
tft.println(fvalue, 0); // no decimal places
tft.println(fvalue, 1); // 1 decimal place
tft.println(fvalue, 2); // 2 decimal places
tft.println(fvalue, 5); // 5 decimal places
delay(5000);
// Get ready for the next demo while we have this font loaded
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0); // Set cursor at top left of screen
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.println("Wrong and right ways to");
tft.println("print changing values...");
tft.unloadFont(); // Remove the font to recover memory used
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Large font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tft.loadFont(AA_FONT_LARGE); // Load another different font
//tft.fillScreen(TFT_BLACK);
// Draw changing numbers - does not work unless a filled rectangle is drawn over the old text
for (int i = 0; i <= 20; i++)
{
tft.setCursor(50, 50);
tft.print(" "); // Overprinting old number with spaces DOES NOT WORK!
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setCursor(50, 50);
tft.print(i / 10.0, 1);
tft.fillRect (50, 90, 60, 40, TFT_BLACK); // Overprint with a filled rectangle
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setCursor(50, 90);
tft.print(i / 10.0, 1);
//delay (200);
}
delay(5000);
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Large font text wrapping
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_YELLOW, TFT_BLACK); // Change the font colour and the background colour
tft.setCursor(0, 0); // Set cursor at top left of screen
tft.println("Large font!");
tft.setTextWrap(true); // Wrap on width
tft.setTextColor(TFT_CYAN, TFT_BLACK);
tft.println("Long lines wrap to the next line");
tft.setTextWrap(false, false); // Wrap on width and height switched off
tft.setTextColor(TFT_MAGENTA, TFT_BLACK);
tft.println("Unless text wrap is switched off");
tft.unloadFont(); // Remove the font to recover memory used
delay(8000);
}
/*
This sketch is the same as the Font_Demo_2 example, except the fonts in this
example are in a FLASH (program memory) array. This means that processors
such as the STM32 series that are not supported by a SPIFFS library can use
smooth (anti-aliased) fonts.
*/
/*
There are four different methods of plotting anti-aliased fonts to the screen.
This sketch uses method 2, using graphics calls plotting direct to the TFT:
tft.drawString(string, x, y);
tft.drawNumber(integer, x, y);
tft.drawFloat(float, dp, x, y); // dp = number of decimal places
setTextDatum() and setTextPadding() functions work with those draw functions.
This method is good for static text that does not change often because changing
values may flicker.
*/
// A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI
// https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font
// This sketch uses font files created from the Noto family of fonts:
// https://www.google.com/get/noto/
#include "NotoSansBold15.h"
#include "NotoSansBold36.h"
// The font names are arrays references, thus must NOT be in quotes ""
#define AA_FONT_SMALL NotoSansBold15
#define AA_FONT_LARGE NotoSansBold36
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
void setup(void) {
Serial.begin(250000);
tft.begin();
tft.setRotation(1);
}
void loop() {
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set the font colour and the background colour
tft.setTextDatum(TC_DATUM); // Top Centre datum
int xpos = tft.width() / 2; // Half the screen width
int ypos = 10;
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Small font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tft.loadFont(AA_FONT_SMALL); // Must load the font first
tft.drawString("Small 15pt font", xpos, ypos);
ypos += tft.fontHeight(); // Get the font height and move ypos down
tft.setTextColor(TFT_GREEN, TFT_BLACK);
// If the string does not fit the screen width, then the next character will wrap to a new line
tft.drawString("Ode To A Small Lump Of Green Putty I Found In My Armpit One Midsummer Morning", xpos, ypos);
tft.setTextColor(TFT_GREEN, TFT_BLUE); // Background colour does not match the screen background!
tft.drawString("Anti-aliasing causes odd looking shadow effects if the text and screen background colours are not the same!", xpos, ypos + 60);
tft.unloadFont(); // Remove the font to recover memory used
delay(5000);
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Large font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tft.loadFont(AA_FONT_LARGE); // Load another different font
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLUE); // Change the font colour and the background colour
tft.drawString("36pt font", xpos, ypos);
ypos += tft.fontHeight(); // Get the font height and move ypos down
// Set text padding to 100 pixels wide area to over-write old values on screen
tft.setTextPadding(100);
// Draw changing numbers - likely to flicker using this plot method!
for (int i = 0; i <= 20; i++) {
tft.drawFloat(i / 10.0, 1, xpos, ypos);
delay (200);
}
tft.unloadFont(); // Remove the font to recover memory used
delay(5000);
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Setting the 12 datum positions works with free fonts
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Integer numbers, floats and strings can be drawn relative to a x,y datum, e.g.:
// tft.drawNumber( 123, x, y);
// tft.drawFloat( 1.23, dp, x, y); // Where dp is number of decimal places to show
// tft.drawString( "Abc", x, y);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_DARKGREY, TFT_BLACK);
// Use middle of screen as datum
xpos = tft.width() /2;
ypos = tft.height()/2;
tft.loadFont(AA_FONT_SMALL);
tft.setTextDatum(TL_DATUM);
tft.drawString("[Top left]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(TC_DATUM);
tft.drawString("[Top centre]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(TR_DATUM);
tft.drawString("[Top right]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(ML_DATUM);
tft.drawString("[Middle left]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.drawString("[Middle centre]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MR_DATUM);
tft.drawString("[Middle right]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(BL_DATUM);
tft.drawString("[Bottom left]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(BC_DATUM);
tft.drawString("[Bottom centre]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(BR_DATUM);
tft.drawString("[Bottom right]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(L_BASELINE);
tft.drawString("[Left baseline]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(C_BASELINE);
tft.drawString("[Centre baseline]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(R_BASELINE);
tft.drawString("[Right baseline]", xpos, ypos);
drawDatumMarker(xpos, ypos);
delay(1000);
tft.unloadFont(); // Remove the font to recover memory used
delay(4000);
}
// Draw a + mark centred on x,y
void drawDatumMarker(int x, int y)
{
tft.drawLine(x - 5, y, x + 5, y, TFT_GREEN);
tft.drawLine(x, y - 5, x, y + 5, TFT_GREEN);
}
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
This sketch is the same as the Font_Demo_3 example, except the fonts in this
example are in a FLASH (program memory) array. This means that processors
such as the STM32 series that are not supported by a SPIFFS library can use
smooth (anti-aliased) fonts.
*/
/*
There are four different methods of plotting anti-aliased fonts to the screen.
This sketch uses method 3, the font characters are first plotted in a Sprite, then the
Sprite is pushed to the screen. This method is very flexible and the Sprite can be
created, deleted, resized as needed. To render anit-aliased fonts well the Sprite
needs to be 16 bit. The fonts will render in 1 bit per pixel sprites but there
will then be no anti-aliasing. Using 1 bit per pixel Sprites is however useful
to use the extended Unicode range in fonts on mono displays like ePaper.
A single Sprite can be re-used for plotting different values and graphics to
different positions on the screen. This makes this method a very powerful display tool,
for example round buttons can be created, making use of transparent colour plotting.
*/
// A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI
// https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font
// This sketch uses font files created from the Noto family of fonts:
// https://www.google.com/get/noto/
#include "NotoSansBold15.h"
#include "NotoSansBold36.h"
#include "NotoSansMonoSCB20.h"
// The font names are arrays references, thus must NOT be in quotes ""
#define AA_FONT_SMALL NotoSansBold15
#define AA_FONT_LARGE NotoSansBold36
#define AA_FONT_MONO NotoSansMonoSCB20 // NotoSansMono-SemiCondensedBold 20pt
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite class needs to be invoked
void setup(void) {
Serial.begin(250000);
tft.begin();
tft.setRotation(1);
spr.setColorDepth(16); // 16 bit colour needed to show antialiased fonts
}
void loop() {
tft.fillScreen(TFT_DARKGREY);
int xpos = tft.width() / 2; // Half the screen width
int ypos = 50;
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Small font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
spr.loadFont(AA_FONT_SMALL); // Must load the font first into the sprite class
spr.createSprite(100, 50); // Create a sprite 100 pixels wide and 50 high
spr.fillSprite(TFT_BLUE);
spr.drawRect(0, 0, 100, 50, TFT_WHITE); // Draw sprite border outline (so we see extent)
spr.setTextColor(TFT_YELLOW, TFT_DARKGREY); // Set the sprite font colour and the background colour
spr.setTextDatum(MC_DATUM); // Middle Centre datum
spr.drawString("15pt font", 50, 25 ); // Coords of middle of 100 x 50 Sprite
spr.pushSprite(10, 10); // Push to TFT screen coord 10, 10
spr.pushSprite(10, 70, TFT_BLUE); // Push to TFT screen, TFT_BLUE is transparent
spr.unloadFont(); // Remove the font from sprite class to recover memory used
delay(4000);
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Large font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tft.fillScreen(TFT_BLACK);
// Beware: Sprites are a differerent "class" to TFT, so different fonts can be loaded
// in the tft and sprite instances, so load the font in the class instance you use!
// In this example this means the spr. instance.
spr.loadFont(AA_FONT_LARGE); // Load another different font into the sprite instance
// 100 x 50 sprite was created above and still exists...
spr.fillSprite(TFT_GREEN);
spr.setTextColor(TFT_BLACK, TFT_GREEN); // Set the font colour and the background colour
spr.setTextDatum(MC_DATUM); // Middle Centre datum
spr.drawString("Fits", 50, 25); // Make sure text fits in the Sprite!
spr.pushSprite(10, 10); // Push to TFT screen coord 10, 10
spr.fillSprite(TFT_RED);
spr.setTextColor(TFT_WHITE, TFT_RED); // Set the font colour and the background colour
spr.drawString("Too big", 50, 25); // Text is too big to all fit in the Sprite!
spr.pushSprite(10, 70); // Push to TFT screen coord 10, 70
// Draw changing numbers - no flicker using this plot method!
// >>>> Note: it is best to use drawNumber() and drawFloat() for numeric values <<<<
// >>>> this reduces digit position movement when the value changes <<<<
// >>>> drawNumber() and drawFloat() functions behave like drawString() and are <<<<
// >>>> supported by setTextDatum() and setTextPadding() <<<<
spr.setTextDatum(TC_DATUM); // Top Centre datum
spr.setTextColor(TFT_WHITE, TFT_BLUE); // Set the font colour and the background colour
for (int i = 0; i <= 200; i++) {
spr.fillSprite(TFT_BLUE);
spr.drawFloat(i / 100.0, 2, 50, 10); // draw with 2 decimal places at 50,10 in sprite
spr.pushSprite(10, 130); // Push to TFT screen coord 10, 130
delay (20);
}
spr.unloadFont(); // Remove the font to recover memory used
spr.deleteSprite(); // Recover memory
delay(1000);
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Mono spaced font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
spr.loadFont(AA_FONT_MONO); // Mono spaced fonts have fixed intercharacter gaps to
// aid formatting
int bnum = 1;
// Example of drawing buttons
for (int j = 0; j < 4; j++)
{
for (int k = 0; k < 4; k++)
{
int x = 120 + k * 45;
int y = 40 + j * 30;
button(x, y, bnum++);
}
}
for (int i = 0; i < 100; i++)
{
button(120, 160, i);
delay(50);
}
spr.unloadFont();
delay(8000);
}
// #########################################################################
// Draw a number in a rounded rectangle with some transparent pixels
// Load the font before calling
// #########################################################################
void button(int x, int y, int num )
{
// Size of sprite
#define IWIDTH 40
#define IHEIGHT 25
// Create a 16 bit sprite 40 pixels wide, 25 high (2000 bytes of RAM needed)
spr.setColorDepth(16);
spr.createSprite(IWIDTH, IHEIGHT);
// Fill it with black (this will be the transparent colour this time)
spr.fillSprite(TFT_BLACK);
// Draw a background for the numbers
spr.fillRoundRect( 0, 0, IWIDTH, IHEIGHT, 8, TFT_RED);
spr.drawRoundRect( 0, 0, IWIDTH, IHEIGHT, 8, TFT_WHITE);
// Set the font parameters
// Set text coordinate datum to middle centre
spr.setTextDatum(MC_DATUM);
// Set the font colour and the background colour
spr.setTextColor(TFT_WHITE, TFT_RED);
// Draw the number
spr.drawNumber(num, IWIDTH/2, 1 + IHEIGHT/2);
// Push sprite to TFT screen CGRAM at coordinate x,y (top left corner)
// All black pixels will not be drawn hence will show as "transparent"
spr.pushSprite(x, y, TFT_BLACK);
// Delete sprite to free up the RAM
spr.deleteSprite();
}
/*
This sketch is the same as the Font_Demo_4 example, except the fonts in this
example are in a FLASH (program memory) array. This means that processors
such as the STM32 series that are not supported by a SPIFFS library can use
smooth (anti-aliased) fonts.
*/
/*
There are four different methods of plotting anti-aliased fonts to the screen.
This sketch uses method 4, printing "String" or character array types only to screen,
via a Sprite. The Sprite must NOT have been created already. The printToSprite()
function automatically creates a sprite of a minimal size to contain the String,
then plots to screen at the "tft" cursor position. Printing via a sprite draws the
text faster on the screen. This method minimises flicker but uses RAM for the Sprite,
the Sprite is automatically deleted after plotting to the TFT.
Number and float types must be converted to strings to use printToSprite() e.g.:
spr.printToSprite( (String) number );
spr.printToSprite( (String) (number * 55 / 1.23) ); // Put calculations within brackets
The key advantage of this method is that you do not need to calculate the size of sprite
needed to contain the text, the library does that for you. The library also fills the
the sprite with text background colour for you.
printToSprite() has a second purpose, if the sprite has been created already the String
will be printed into the Sprite at the "sprite" cursor position, which is
different to the "tft" cursor position. In this case the Sprite is not deleted and
you must use pushSprite() to plot on the screen. This method is not used in this sketch.
because in general it is better to use drawString() in an already created sprite.
printToSprite() will NOT move the tft cursor.
*/
// A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI
// https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font
// This sketch uses font files created from the Noto family of fonts:
// https://www.google.com/get/noto/
#include "NotoSansBold15.h"
#include "NotoSansBold36.h"
// The font names are arrays references, thus must NOT be in quotes ""
#define AA_FONT_SMALL NotoSansBold15
#define AA_FONT_LARGE NotoSansBold36
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite class needs to be invoked
void setup(void) {
Serial.begin(250000);
tft.begin();
tft.setRotation(1);
spr.setColorDepth(16); // 16 bit colour needed to show antialiased fonts
}
void loop() {
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set the font colour and the background colour
tft.setTextDatum(TC_DATUM); // Top Centre datum
int xpos = tft.width() / 2; // Half the screen width
int ypos = 50;
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Small font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
spr.loadFont(AA_FONT_SMALL); // Must load the font first into the sprite class
spr.setTextColor(TFT_YELLOW, TFT_BLACK); // Set the sprite font colour and the background colour
tft.setCursor(xpos - 50, ypos); // Set the tft cursor position, yes tft position!
spr.printToSprite("Small 15pt font"); // Prints to tft cursor position, tft cursor NOT moved
ypos += spr.fontHeight(); // Get the font height and move ypos down
spr.unloadFont(); // Remove the font from sprite class to recover memory used
delay(4000);
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Large font
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tft.fillScreen(TFT_BLACK);
spr.loadFont(AA_FONT_LARGE); // Load another different font
spr.setTextColor(TFT_WHITE, TFT_BLUE); // Set the font colour and the background colour
tft.setCursor(xpos - 90, ypos); // Set the tft cursor position
spr.printToSprite("36pt font"); // Text is rendered via a minimally sized sprite
ypos += spr.fontHeight(); // Get the font height and move ypos down
// Draw changing numbers - no flicker using this plot method!
for (int i = 0; i <= 200; i++) {
tft.setCursor(10, 10);
// Number is converted to String type by (String) (number)
spr.printToSprite(" " + (String) (i / 100.0) + " "); // Space padding helps over-write old numbers
delay (20);
}
spr.unloadFont(); // Remove the font to recover memory used
delay(8000);
}
/*
Information notes only:
======================
//These are the text plotting alignment (reference datum point)
TL_DATUM = Top left (default)
TC_DATUM = Top centre
TR_DATUM = Top right
ML_DATUM = Middle left
MC_DATUM = Middle centre
MR_DATUM = Middle right
BL_DATUM = Bottom left
BC_DATUM = Bottom centre
BR_DATUM = Bottom right
L_BASELINE = Left character baseline (Line the 'A' character would sit on)
C_BASELINE = Centre character baseline
R_BASELINE = Right character baseline
// Basic colours already defined:
TFT_BLACK 0x0000
TFT_NAVY 0x000F
TFT_DARKGREEN 0x03E0
TFT_DARKCYAN 0x03EF
TFT_MAROON 0x7800
TFT_PURPLE 0x780F
TFT_OLIVE 0x7BE0
TFT_LIGHTGREY 0xC618
TFT_DARKGREY 0x7BEF
TFT_BLUE 0x001F
TFT_GREEN 0x07E0
TFT_CYAN 0x07FF
TFT_RED 0xF800
TFT_MAGENTA 0xF81F
TFT_YELLOW 0xFFE0
TFT_WHITE 0xFFFF
TFT_ORANGE 0xFDA0
TFT_GREENYELLOW 0xB7E0
TFT_PINK 0xFC9F
*/
/*
Information notes only:
======================
//These are the text plotting alignment (reference datum point)
TL_DATUM = Top left (default)
TC_DATUM = Top centre
TR_DATUM = Top right
ML_DATUM = Middle left
MC_DATUM = Middle centre
MR_DATUM = Middle right
BL_DATUM = Bottom left
BC_DATUM = Bottom centre
BR_DATUM = Bottom right
L_BASELINE = Left character baseline (Line the 'A' character would sit on)
C_BASELINE = Centre character baseline
R_BASELINE = Right character baseline
// Basic colours already defined:
TFT_BLACK 0x0000
TFT_NAVY 0x000F
TFT_DARKGREEN 0x03E0
TFT_DARKCYAN 0x03EF
TFT_MAROON 0x7800
TFT_PURPLE 0x780F
TFT_OLIVE 0x7BE0
TFT_LIGHTGREY 0xC618
TFT_DARKGREY 0x7BEF
TFT_BLUE 0x001F
TFT_GREEN 0x07E0
TFT_CYAN 0x07FF
TFT_RED 0xF800
TFT_MAGENTA 0xF81F
TFT_YELLOW 0xFFE0
TFT_WHITE 0xFFFF
TFT_ORANGE 0xFDA0
TFT_GREENYELLOW 0xB7E0
TFT_PINK 0xFC9F
*/
/*
Information notes only:
======================
Note: it is best to use drawNumber() and drawFloat() for numeric values
this reduces digit position movement when the value changes
drawNumber() and drawFloat() functions behave like drawString() and are
supported by setTextDatum() and setTextPadding()
//These are the text plotting alignment (reference datum point)
TL_DATUM = Top left (default)
TC_DATUM = Top centre
TR_DATUM = Top right
ML_DATUM = Middle left
MC_DATUM = Middle centre
MR_DATUM = Middle right
BL_DATUM = Bottom left
BC_DATUM = Bottom centre
BR_DATUM = Bottom right
L_BASELINE = Left character baseline (Line the 'A' character would sit on)
C_BASELINE = Centre character baseline
R_BASELINE = Right character baseline
// Basic colours already defined:
TFT_BLACK 0x0000
TFT_NAVY 0x000F
TFT_DARKGREEN 0x03E0
TFT_DARKCYAN 0x03EF
TFT_MAROON 0x7800
TFT_PURPLE 0x780F
TFT_OLIVE 0x7BE0
TFT_LIGHTGREY 0xC618
TFT_DARKGREY 0x7BEF
TFT_BLUE 0x001F
TFT_GREEN 0x07E0
TFT_CYAN 0x07FF
TFT_RED 0xF800
TFT_MAGENTA 0xF81F
TFT_YELLOW 0xFFE0
TFT_WHITE 0xFFFF
TFT_ORANGE 0xFDA0
TFT_GREENYELLOW 0xB7E0
TFT_PINK 0xFC9F
*/
/*
Information notes only:
======================
//These are the text plotting alignment (reference datum point)
TL_DATUM = Top left (default)
TC_DATUM = Top centre
TR_DATUM = Top right
ML_DATUM = Middle left
MC_DATUM = Middle centre
MR_DATUM = Middle right
BL_DATUM = Bottom left
BC_DATUM = Bottom centre
BR_DATUM = Bottom right
L_BASELINE = Left character baseline (Line the 'A' character would sit on)
C_BASELINE = Centre character baseline
R_BASELINE = Right character baseline
// Basic colours already defined:
TFT_BLACK 0x0000
TFT_NAVY 0x000F
TFT_DARKGREEN 0x03E0
TFT_DARKCYAN 0x03EF
TFT_MAROON 0x7800
TFT_PURPLE 0x780F
TFT_OLIVE 0x7BE0
TFT_LIGHTGREY 0xC618
TFT_DARKGREY 0x7BEF
TFT_BLUE 0x001F
TFT_GREEN 0x07E0
TFT_CYAN 0x07FF
TFT_RED 0xF800
TFT_MAGENTA 0xF81F
TFT_YELLOW 0xFFE0
TFT_WHITE 0xFFFF
TFT_ORANGE 0xFDA0
TFT_GREENYELLOW 0xB7E0
TFT_PINK 0xFC9F
*/
{
"name": "TFT_eSPI",
"version": "2.0.4",
"version": "2.1.0",
"keywords": "Arduino, tft, ePaper, display, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789, RM68140",
"description": "A TFT and ePaper SPI graphics library with optimisation for ESP8266, ESP32 and STM32",
"repository":
......
name=TFT_eSPI
version=2.0.4
version=2.1.0
author=Bodmer
maintainer=Bodmer
sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment