TFT LCD Virtual Segment Display Library for Arduino
I am building a chess clock using an Arduino UNO R3 microcontroller and a TFT LCD touch screen.
The Arduino UNO has an ATmega328P microcontroller running at 16 MHz. The processor frequency is low and the SRAM memory is limited to 2 KB. This makes using a TFT LCD screen not a good choice for displaying images with a lot of movement or large text without flickering when updating. Techniques such as double buffering are also not practical due to the limited memory available.
After several attempts using fonts from standard Arduino libraries to show the player's clocks and obtaining bad results, I have decided to create my own library that emulates seven-segment displays, fully configurable in sizes. and colors and that allows a fast update without any flicker. https://github.com/javagoza/TFTVirtualSegmentDisplay
This is my first gift of the year to the entire Arduino fan community.
Hardware used
This library is compatible with all TFT LCD screens an Arduino models that the Adafruit TFTLCD Library supports.
For the examples shown, I am using:
You can also choose this one from Adafruit:
The library in action
Here the library refreshing the display each 10 ms,
TFT Virtual Segment Display for Arduino
This library allows to display different virtual segment displays on a TFT LCD using Adafruit TFTLCD Library
Constructor
/*! @brief Create a TFTSevenSegmentClockDisplay represent a clock display with 4 or 6 seven segment modules @param tft pointer to Adafruit_TFTLCD @param x x coordinate @param y y coordinate @param w seven segment module width @param h seven segment module height @param onColor 565 segment color when led segments are in on state @param offColor 565 segment color when led segment are in off state @param ledWidth width in pixels of each segment led @param showHours true show clock with hours-minutes-seconds, false show only minutes-seconds @param secondsHeightRatio reduction factor of the size of the digits representing the seconds */ TFTSevenSegmentClockDisplay::TFTSevenSegmentClockDisplay( Adafruit_TFTLCD* tft, int16_t x = 0, int16_t y = 0, int16_t w = 16, int16_t h = 32, uint16_t onColor = 255, uint16_t offColor = 0, int16_t ledWidth = 3, boolean showHours = true, float secondsHeightRatio = 3 / 4);
Example 1
Create a Clock Display with WHITE segment LED in on state, dark grey in off state, 6 pixels wide segments, showing hours subgroup, 3/4 height reduction for seconds subgroup.
TFTSevenSegmentClockDisplay clockDisplayA(&tft, 0, 50, 40, 64, WHITE, tft.color565(20, 20, 20), 6, true, 3.0 / 4.0);
clockDisplayA.displaySeconds(86399, true);
Example 2
Create a Clock Display with YELLOW segment LED in on state, dark grey in off state, 10 pixels wide segments, not showing hours subgroup, 1/2 height reduction for seconds subgroup.
TFTSevenSegmentClockDisplay clockDisplayA(&tft, 0, 50, 80, 160, YELLOW, tft.color565(20, 20, 20), 10, false, .5);
clockDisplayA.displaySeconds(86399, false);
This is not UNIX time but seconds counting from zero.
Testing the TFT LCD Virtual Clock Display Library: Making a Chess Clock.
Github Repository
You can download the latest version of the library at:
https://github.com/javagoza/TFTVirtualSegmentDisplay
Project blogs
Arduino UNO Digital Chess Clock
Arduino UNO Chess Clock TFT LCD Virtual Clock Display Library
Top Comments