element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Build a Present
  • Challenges & Projects
  • Project14
  • Build a Present
  • More
  • Cancel
Build a Present
Blog Arduino UNO Chess Clock TFT LCD Virtual Clock Display Library
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: javagoza
  • Date Created: 1 Jan 2022 6:12 PM Date Created
  • Views 23500 views
  • Likes 10 likes
  • Comments 6 comments
  • clock
  • lcd
  • tft
  • library
  • chess
  • buildapresentch
  • arduino
Related
Recommended

Arduino UNO Chess Clock TFT LCD Virtual Clock Display Library

javagoza
javagoza
1 Jan 2022
Arduino UNO Chess Clock TFT LCD Virtual Clock Display Library

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.

image

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:

  • Arduino UNO
  • ELEGOO UNO R3 2.8 Inches TFT 

You can also choose this one from Adafruit:

  • adafruit TFT Touch Shield, 2.8", Arduino, Resistive Touch Screen

Arduino UNO R3 and TFT LCD Display

The library in action

Here the library refreshing the display each 10 ms, 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

TFT Virtual Segment Display for Arduino

This library allows to display different virtual segment displays on a TFT LCD using Adafruit TFTLCD Library

image

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);

image

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);

image

This is not UNIX time but seconds counting from zero.

Testing the TFT LCD Virtual Clock Display Library: Making a Chess Clock.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Testing 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

  • Sign in to reply

Top Comments

  • shabaz
    shabaz over 3 years ago +1
    Hi Enrique, Great job! The font looks awesome. This would also make the ultimate kitchen timer.. (once encountered one that had the seconds running in the background, so when you hit Start, it always…
  • AndyL1952
    AndyL1952 over 2 years ago in reply to javagoza

    Thank you for a prompt reply....

    I reached out to Elegoo Technical Support  - and they came back almost immediately.

    I was very impressed.

    They sent me a different pin_magic.h file to overwrite the pin_magic.h file in the adafruit TFTLCD-Library-master file.

    That means that the Adafruit example files now run on the Mega as they did on the UNO.

    So .. so should your lib - but I havnt got that far yet.

    Here's a photo of my 'latest' clock.

    Seems to be an obsession! image

    I tried to attach the pin_magic.h file - but couldnt.

    Keep up the good work! This is such a useful display.

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • javagoza
    javagoza over 2 years ago in reply to AndyL1952

    Hi, I'm glad you found the display library interesting. I have not tested it with an Arduino mega yet but I know of some user who is adapting it to the mega.

    https://github.com/javagoza/TFTVirtualSegmentDisplay/issues/1

    With the Arduino Mega I used another library, the MCUFRIEND_kbv library as in this project 

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

    see: Mega 2560 Touch Breakout Game - Hackster.io

    prenticedavid/MCUFRIEND_kbv: MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields (github.com)

    I think it is easy to adapt it to that other library.

    It may be enough to change the references to the Adafruit_TFTLCD class by MCUFRIEND_kbv and include them
    #include <Adafruit_TFTLCD.h>
    by
    #include <MCUFRIEND_kbv.h>

    If I have some time this week I can try to do a test if I find any Mega at home.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • AndyL1952
    AndyL1952 over 2 years ago

    Hi Enrique

    What a suberb library! Just love it. Thanks for sharing it.

    I want to use this to update my clock that curerntly uses 8*8 led displays but I have a problem.....

    I am using an Elegoo 2.8TFT screen, and although I get get it to work perfectly with the Uno and Adafruit Lib, when I try to use a Mega - nothing!

    The Elegoo Lib examples work fine with the Mega - but no the Adafruit examples.

    Anyone shed any light on the reasons why?

    Thank you!

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • javagoza
    javagoza over 3 years ago

    I have added a photo and a small video of a first version of the chess clock to check the usability of the resistive touch screen and the visibility of the two clocks on the display. Feedback has been positive and some good suggestions :)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • javagoza
    javagoza over 3 years ago in reply to shabaz

    Thanks Shabaz. Interesting the failure of the timer that you comment and premonitory  Innocent I will try not to forget that lesson for the chess clock.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube