Description

Set the font foreground colour (background is transparent) or with a background colour.

Signature

  • void TFT_eSPI::setTextColor(uint16_t color)
  • void TFT_eSPI::setTextColor(uint16_t fgcolor, uint16_t bgcolor, bool bgfill = false)

Parameters

  • uint16_t color: Text color.
  • uint16_t fgcolor: Foreground color.
  • uint16_t bgcolor: Background color.
  • bool bgfill: Is background filled, by default not.

Result

None.

Example

#include <TFT_eSPI.h>

TFT_eSPI tft = TFT_eSPI();

void setup() {
  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.setTextFont(2); // Set the text font to font number 2
  tft.println("Hello World!");
}

void loop() {
  // nothing to do here, just display the "Hello World!" message
}

Let me explain what each line does:

Note

You need to modify the User_Setup_Select.h file to configure the TFT_eSPI library for your specific TFT display. Additionally, you may need to adjust the pin connections and the TFT_eSPI constructor to match your hardware setup.