// The display also uses hardware SPI, plus #9 & #10
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
#define TFT_CS 15
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_SCLK 18
#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
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 <= 99; i++)
{
tft.setCursor(50, 50);
tft.setTextColor(TFT_GREEN, TFT_BLACK); // TFT_BLACK is used for anti-aliasing only
// By default background fill is off
tft.print(" "); // Overprinting old number with spaces DOES NOT WORK!
tft.setCursor(50, 50);
tft.print(i / 10.0, 1);
// Adding a parameter "true" to the setTextColor() function fills character background
// This extra parameter is only for smooth fonts!
tft.setTextColor(TFT_GREEN, TFT_BLACK, true);
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);
}