AllFreeFontsDemo
/*
Example for TFT_eSPI library
Created by Bodmer 31/12/16
This example draws all fonts (as used by the Adafruit_GFX library) onto the
screen. These fonts are called the GFX Free Fonts (GFXFF) in this library.
The fonts are referenced by a short name, see the Free_Fonts.h file
attached to this sketch.
Other True Type fonts could be converted using the utility within the
"fontconvert" folder inside the library. This converted has also been
copied from the Adafruit_GFX library.
Since these fonts are a recent addition Adafruit do not have a tutorial
available yet on how to use the fontconvert utility. Linux users will
no doubt figure it out! In the meantime there are 48 font files to use
in sizes from 9 point to 24 point, and in normal, bold, and italic or
oblique styles.
This example sketch uses both the print class and drawString() functions
to plot text to the screen.
Make sure LOAD_GFXFF is defined in the User_Setup.h file within the
library folder.
--------------------------- NOTE ----------------------------------------
The free font encoding format does not lend itself easily to plotting
the background without flicker. For values that changes on screen it is
better to use Fonts 1- 8 which are encoded specifically for rapid
drawing with background.
-------------------------------------------------------------------------
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT YOUR DISPLAY TYPE AND ENABLE FONTS ######
#########################################################################
*/
#define TEXT "aA MWyz~12" // Text that will be printed on screen in any font
#include "Free_Fonts.h" // Include the header file attached to this sketch
#include "SPI.h"
#include "TFT_eSPI.h"
// Use hardware SPI
TFT_eSPI tft = TFT_eSPI();
unsigned long drawTime = 0;
void setup(void) {
tft.begin();
tft.setRotation(1);
}
void loop() {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Show all 48 fonts in centre of screen ( x,y coordinate 160,120)
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Where font sizes increase the screen is not cleared as the larger fonts overwrite
// the smaller one with the background color.
// Set text datum to middle centre
tft.setTextDatum(MC_DATUM);
// Set text colour to orange with black background
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.fillScreen(TFT_BLACK); // Clear screen
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF1, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF1); // Select the font
tft.drawString(TEXT, 160, 120, GFXFF);// Print the string name of the font
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF2, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF2);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF3, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF3);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF4, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF4);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF5, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF5);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF6, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF6);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF7, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF7);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF8, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF8);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF9, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF9);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF10, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF10);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF11, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF11);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF12, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF12);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF13, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF13);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF14, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF14);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF15, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF15);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF16, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF16);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF17, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF17);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF18, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF18);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF19, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF19);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF20, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF20);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF21, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF21);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF22, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF22);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF23, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF23);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF24, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF24);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF25, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF25);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF26, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF26);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF27, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF27);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF28, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF28);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF29, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF29);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF30, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF30);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF31, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF31);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF32, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF32);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF33, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF33);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF34, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF34);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF35, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF35);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF36, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF36);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF37, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF37);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF38, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF38);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF39, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF39);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF40, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF40);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF41, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF41);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF42, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF42);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF43, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF43);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF44, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF44);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF45, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF45);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF46, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF46);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF47, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF47);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
//tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18); // Select the font
tft.drawString(sFF48, 160, 60, GFXFF);// Print the string name of the font
tft.setFreeFont(FF48);
tft.drawString(TEXT, 160, 120, GFXFF);
delay(1000);
}
// There follows a crude way of flagging that this example sketch needs fonts which
// have not been enbabled in the User_Setup.h file inside the TFT_HX8357 library.
//
// These lines produce errors during compile time if settings in User_Setup are not correct
//
// The error will be "does not name a type" but ignore this and read the text between ''
// it will indicate which font or feature needs to be enabled
//
// Either delete all the following lines if you do not want warnings, or change the lines
// to suit your sketch modifications.
#ifndef LOAD_GLCD
//ERROR_Please_enable_LOAD_GLCD_in_User_Setup
#endif
#ifndef LOAD_GFXFF
ERROR_Please_enable_LOAD_GFXFF_in_User_Setup!
#endif
SpriteScroll1bit
/*
Sketch to show scrolling of the graphics in sprites.
This sketch scrolls a 1 bit per pixel (1 bpp) Sprite.
In a 1 bit Sprite any color except TFT_BLACK turns a pixel "ON"
TFT_BLACK turns a pixel "OFF".
The 1 bpp Sprite has a unique property that other bit depth Sprites
do not have, you can set the rotation of the coordinate frame e.g.:
spr.setRotation(1);
This is similar to screen rotations, so for example text can
be drawn rotated:
Rotation 0: Normal orientation
Rotation 1: Coordinate frame rotated clockwise 90 degrees
Rotation 2: Coordinate frame rotated clockwise 180 degrees (upside down)
Rotation 3: Coordinate frame rotated clockwise 270 degrees
When pushSprite is used the sprite is drawn with the width and height
staying as created, so the created Sprite itself is not rotated during
rendering. See stext2 sprite example below at line 83.
ON and OFF pixels can be set to any two colors before
rendering to the screen with pushSprite, for example:
tft.setBitmapColor(ON_COLOR, OFF_COLOR);
Scrolling moves the pixels in a defined rectangle within
the Sprite. By defalt the whole sprite is scrolled.
The gap left by scrolling is filled with a defined color.
Example for library:
https://github.com/Bodmer/TFT_eSPI
A Sprite is notionally an invisible graphics screen that is
kept in the processors RAM. Graphics can be drawn into the
Sprite just as it can be drawn directly to the screen. Once
the Sprite is completed it can be plotted onto the screen in
any position. If there is sufficient RAM then the Sprite can
be the same size as the screen and used as a frame buffer.
A 1 bit Sprite occupies (width * height)/8 bytes in RAM.
*/
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite graph1 = TFT_eSprite(&tft); // Sprite object graph1
TFT_eSprite stext1 = TFT_eSprite(&tft); // Sprite object stext1
TFT_eSprite stext2 = TFT_eSprite(&tft); // Sprite object stext2
int graphVal = 1;
int delta = 1;
int grid = 0;
int tcount = 0;
//==========================================================================================
void setup() {
tft.init();
tft.fillScreen(TFT_BLACK);
// Create a sprite for the graph
graph1.setColorDepth(1);
graph1.createSprite(128, 61);
graph1.fillSprite(TFT_BLACK); // Note: Sprite is filled with black when created
// The scroll area is set to the full sprite size upon creation of the sprite
// but we can change that by defining a smaller area using "setScrollRect()"if needed
// parameters are x,y,w,h,color as in drawRect(), the color fills the gap left by scrolling
//graph1.setScrollRect(64, 0, 64, 61, TFT_BLACK); // Try this line to change the graph scroll area
// Create a sprite for the scrolling numbers
stext1.setColorDepth(1);
stext1.createSprite(32, 64);
stext1.fillSprite(TFT_BLACK); // Fill sprite with blue
stext1.setScrollRect(0, 0, 32, 64, TFT_BLACK); // here we set scroll gap fill color to blue
stext1.setTextColor(TFT_WHITE); // White text, no background
stext1.setTextDatum(BR_DATUM); // Bottom right coordinate datum
// Create a sprite for Hello World
stext2.setColorDepth(1);
stext2.createSprite(16, 80); // Narrow and tall
stext2.setRotation(1); // Plot with 90 deg. clockwise rotation
stext2.fillSprite(TFT_BLACK);
stext2.setScrollRect(0, 0, 40, 16, TFT_BLACK); // Scroll the "Hello" in the first 40 pixels
stext2.setTextColor(TFT_WHITE); // White text, no background
}
//==========================================================================================
void loop() {
// Draw point in graph1 sprite at far right edge (this will scroll left later)
graph1.drawFastVLine(127, 60 - graphVal, 2, TFT_WHITE); // draw 2 pixel point on graph
// Draw number in stext1 sprite at 31,63 (bottom right datum set)
stext1.drawNumber(graphVal, 31, 63, 2); // plot value in font 2
// Push the sprites onto the TFT at specied coordinates
tft.setBitmapColor(TFT_WHITE, TFT_BLUE); // Specify the colors of the ON and OFF pixels
graph1.pushSprite(0, 0);
tft.setBitmapColor(TFT_GREEN, TFT_BLACK);
stext1.pushSprite(0, 64);
tft.setBitmapColor(TFT_BLACK, TFT_YELLOW);
stext2.pushSprite(60, 70);
// Change the value to plot
graphVal += delta;
// If the value reaches a limit, then change delta of value
if (graphVal >= 60) {
delta = -1; // ramp down value
} else if (graphVal <= 1) {
delta = +1; // ramp up value
}
delay(50); // wait so things do not scroll too fast
// Now scroll the sprites scroll(dt, dy) where:
// dx is pixels to scroll, left = negative value, right = positive value
// dy is pixels to scroll, up = negative value, down = positive value
graph1.scroll(-1, 0); // scroll graph 1 pixel left, 0 up/down
stext1.scroll(0, -16); // scroll stext 0 pixels left/right, 16 up
stext2.scroll(1); // scroll stext 1 pixel right, up/down default is 0
// Draw the grid on far right edge of sprite as graph has now moved 1 pixel left
grid++;
if (grid >= 10) {
// Draw a vertical line if we have scrolled 10 times (10 pixels)
grid = 0;
graph1.drawFastVLine(127, 0, 61, TFT_WHITE); // draw line on graph
} else {
// Otherwise draw points spaced 10 pixels for the horizontal grid lines
for (int p = 0; p <= 60; p += 10) {
graph1.drawPixel(127, p, TFT_WHITE);
}
}
tcount--;
if (tcount <= 0) {
// If we have scrolled 40 pixels the redraw text
tcount = 40;
stext2.drawString("Hello World", 6, 0, 2); // draw at 6,0 in sprite, font 2
}
} // Loop back and do it all again
//==========================================================================================