Introduction
This tutorial discusses a few more functions regarding the color and size of text on evive’s TFT Display using functions from the TFT library in Arduino IDE.
TFT Colour
You can change the color of the text using the following function:
tft.setTextColor(color);
where color can be any of these predefined colors:
- ST7735_BLACK
- ST7735_BLUE
- ST7735_RED
- ST7735_GREEN
- ST7735_CYAN
- ST7735_MAGENTA
- ST7735_YELLOW
- ST7735_WHITE
Apart from this function, other functions can also have these colors in their argument.
Below is an example showing how to change the color of the text on the screen:
/*
This Program demonstrates various colours on TFT display
made for evive platform.
Created by Nihar Shah.
This code is in public domain.
Explore more on : https://thestempedia.com/tutorials/tft-text-manipulation/
*/
#include <evive.h>
void setup() {
Serial.begin(250000);
tft.init(INITR_BLACKTAB);
tft.setRotation(1);
Serial.println("Initialized");
tft.fillScreen(ST7735_BLACK);
}
void loop() {
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.setCursor(0, 10);
tft.println("Hello World");
tft.println("");
tft.println("My name is evive and this is TFT display in white colour.");
delay(2000);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.setCursor(0, 10);
tft.println("Hello World");
tft.println("");
tft.println("My name is evive and this is TFT display in red colour.");
delay(2000);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(1);
tft.setCursor(0, 10);
tft.println("Hello World");
tft.println("");
tft.println("My name is evive and this is TFT display in blue colour.");
delay(2000);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.setCursor(0, 10);
tft.println("Hello World");
tft.println("");
tft.println("My name is evive and this is TFT display in yellow colour.");
delay(2000);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_GREEN);
tft.setTextSize(1);
tft.setCursor(0, 10);
tft.println("Hello World");
tft.println("");
tft.println("My name is evive and this is TFT display in green colour.");
delay(2000);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_MAGENTA);
tft.setTextSize(1);
tft.setCursor(0, 10);
tft.println("Hello World");
tft.println("");
tft.println("My name is evive and this is TFT display in Magenta colour.");
delay(2000);
tft.fillScreen(ST7735_BLACK);
}
Instead of setting colors manually, it is possible to put the responsibility of selecting any random color on the shoulders of Arduino IDE. It can be done with the help of the function given below:
tft.Color565(uint8_t r, uint8_t g, uint8_t b);
where r, g, and b are the red, green, and blue values ranging from 0 to 255.
TFT Text Size
You can vary the size of the text using the function shown below:
tft.setTextSize(unit8_t size);
Below is the Arduino sketch showing the use of the function for changing the size of the text:
/*
Using TFT Display to change text size.
Created by Nihar Shah.
This code is in Public domain.
Explore more on : https://thestempedia.com/tutorials/tft-text-manipulation/
*/
#include <evive.h>
void setup() {
Serial.begin(9600);
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
tft.setRotation(1);
Serial.println("Initialized");
tft.fillScreen(ST7735_BLACK);
}
void loop() {
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(0,0);
tft.setTextSize(1);
tft.println("S1");
delay(1000);
tft.setTextSize(2);
tft.println("S2");
delay(1000);
tft.setTextSize(3);
tft.println("S3");
delay(1000);
tft.setTextSize(4);
tft.println("S4");
delay(1000);
tft.setTextSize(5);
tft.println("S5");
delay(1000);
}
Conclusion
In conclusion, this lesson has discussed two functions from the TFT library in Arduino IDE that can be used to manipulate the color and size of text on evive’s TFT Display. The first function, setTextColor(), allows you to set the color of the text, while the second function, setTextSize(), allows you to set the size of the text. With this tutorial, you should now have a better understanding of how to manipulate the text displayed on evive’s TFT Display.