Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
![]() |
|
This is the digital clock project using an ST7735S 0.96" 80x160 SPI colour display. The circuit includes a 3v Arduino Pro Mini and the timekeeping is from a DS3231 RTC. The circuit fits on a standard breadboard and will run from a 3V input to the raw of the arduino.
The display shows the time, day of the week, the date and the temperature.
As yet this design does not consider updating during BST GMT changes, and presumes that the time of the RTC is already correctly set using the example contained in the DS3231 library
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <DS3231.h> //https://github.com/NorthernWidget/DS3231/releases
#include <Wire.h>
#define TFT_RST -1
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
DS3231 myRTC;
// inverted color definitions
#define BLACK 0xFFFF
#define WHITE 0x0000
#define BLUE 0x07FF
#define RED 0xFFE0
#define GREEN 0xF81F
#define YELLOW 0xF800
#define BROWN 0x9F6D
#define L_BLUE 0x51E4
byte L_Hour = 18; // Last Hour
byte L_Min = 43; // Last Minute
byte L_Sec = 10; // Last Second
byte L_Dow = 6; // Last Day Of The Week
byte L_Date = 11; // Last Date
byte L_Month = 11; // Last Month
byte L_Temp = 28; // Last Temperature
byte L_Year; // Last Year
byte YEAR = 20; // Year 2000
byte YEAR_2; // Last 2 digits of the year
byte Sec,Min,HOUR,Dow,Date,MONTH,Temp; // Variables from RTC
bool h12Flag,pmFlag; //Unused 12h pm Flags
bool century = false;
String DAYS_OF_WEEK [] {"Dummy","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
void setup () {
tft.initR (INITR_BLACKTAB);
Wire.begin();
tft.setRotation (3); // Display Lasdscape
tft.fillScreen (BLACK);
LinesDraw(); // Draw Lines Routine
MONTH = myRTC.getMonth(century);
if (century) { // Year 2100
YEAR = 21;
}
YEAR_2 = myRTC.getYear();
L_Year = YEAR_2;
TextDraw(); // Display All Screen Text
tft.setTextSize(3); // Time Text Size
}
void loop (){
Sec = myRTC.getSecond();
if (Sec != L_Sec) {
Sec_Print();
}
Min = myRTC.getMinute();
if (Min != L_Min) {
Min_Print();
}
HOUR = myRTC.getHour(h12Flag, pmFlag);
if (HOUR != L_Hour) {
Hour_Print();
}
Dow = myRTC.getDoW();
if (L_Dow != Dow) {
tft.setTextSize(2);
Dow_Print();
tft.setTextSize(3);
}
Date = myRTC.getDate();
if (L_Date != Date) {
tft.setTextSize(2);
Date_Print();
MONTH = myRTC.getMonth(century);
if (L_Month != MONTH) {
Month_Print();
YEAR_2 = myRTC.getYear();
if (YEAR_2 != L_Year) {
if (century) {
YEAR = 21;
}
Year_Print();
}
}
tft.setTextSize(3);
}
Temp = myRTC.getTemperature();
if (L_Temp != Temp) {
tft.setTextSize(2);
Temp_Print();
tft.setTextSize(3);
}
}
void LinesDraw() { //Draw The Screen Borders
tft.drawLine(3,54,157,54,RED);
tft.drawLine(3,55,157,55,RED);
tft.drawLine(3,80,157,80,RED);
tft.drawLine(3,81,157,81,RED);
tft.drawLine(112,56,112,79,RED);
tft.drawLine(113,56,113,79,RED);
tft.drawRect(1,26,159,80,RED);
tft.drawRect(2,27,157,78,RED);
tft.fillRect(114,55,44,25,BROWN); // Temperature Box
}
void TextDraw() { //Set up Startup Screen
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(10,30);
tft.print(L_Hour);
tft.print(":");
tft.print(L_Min);
tft.print(":");
tft.print(L_Sec);
tft.setTextSize(2);
tft.setTextColor(GREEN);
tft.setCursor(4 +((108-(DAYS_OF_WEEK [L_Dow].length())*12)/2),60);
tft.print(DAYS_OF_WEEK [L_Dow]);
tft.setTextColor(L_BLUE);
tft.setCursor(20,86);
tft.print("11/11/");
tft.print(YEAR);
tft.print(L_Year);
tft.setTextColor(YELLOW);
tft.setCursor(120,60);
tft.print("28c");
}
void Sec_Print () { // Print Seconds
tft.setTextColor(BLACK);
tft.setCursor(118,30);
if (L_Sec < 10) {
tft.print("0");
}
tft.print(L_Sec);
L_Sec = Sec;
tft.setTextColor(WHITE);
tft.setCursor(118,30);
if (L_Sec < 10) {
tft.print("0");
}
tft.print(L_Sec);
}
void Min_Print () { // Print Minutes
tft.setTextColor(BLACK);
tft.setCursor(64,30);
if (L_Min < 10) {
tft.print("0");
}
tft.print(L_Min);
L_Min = Min;
tft.setTextColor(WHITE);
tft.setCursor(64,30);
if (L_Min < 10) {
tft.print("0");
}
tft.print(L_Min);
}
void Hour_Print () { // Print Hours
tft.setTextColor(BLACK);
tft.setCursor(10,30);
if (L_Hour < 10) {
tft.print("0");
}
tft.print(L_Hour);
L_Hour = HOUR;
tft.setTextColor(WHITE);
tft.setCursor(10,30);
if (L_Hour < 10) {
tft.print("0");
}
tft.print(L_Hour);
}
void Dow_Print() { // Print Days Of The Week String
tft.setTextColor(BLACK);
tft.setCursor(4 +((108-(DAYS_OF_WEEK [L_Dow].length())*12)/2),60);
tft.print(DAYS_OF_WEEK [L_Dow]);
L_Dow = Dow;
tft.setTextColor(GREEN);
tft.setCursor(4 +((108-(DAYS_OF_WEEK [L_Dow].length())*12)/2),60);
tft.print(DAYS_OF_WEEK[L_Dow]);
}
void Date_Print() { // Print Date
tft.setTextColor(BLACK);
tft.setCursor(20,86);
if (L_Date < 10) {
tft.print("0");
}
tft.print(L_Date);
L_Date = Date;
tft.setTextColor(L_BLUE);
tft.setCursor(20,86);
if (L_Date < 10) {
tft.print("0");
}
tft.print(L_Date);
}
void Month_Print(){ // Print Month
// 56x 86y
tft.setTextColor(BLACK);
tft.setCursor(56,86);
if (L_Month < 10) {
tft.print("0");
}
tft.print(L_Month);
L_Month = MONTH;
tft.setTextColor(L_BLUE);
tft.setCursor(56,86);
if (L_Month < 10) {
tft.print("0");
}
tft.print(L_Month);
}
void Temp_Print() { // Print Temperature
tft.setTextColor(BROWN);
tft.setCursor(120,60);
if (L_Temp < 10) {
tft.print("0");
}
tft.print(L_Temp);
L_Temp = Temp;
tft.setTextColor(YELLOW);
tft.setCursor(120,60);
if (L_Temp < 10) {
tft.print("0");
}
tft.print(L_Temp);
}
void Year_Print() { // Print the Year
tft.setTextColor(BLACK);
tft.setCursor(91,86);
tft.print(YEAR);
tft.print(L_Year);
tft.setTextColor(L_BLUE);
tft.setCursor(91,86);
tft.print(YEAR);
L_Year = YEAR_2;
tft.print(L_Year);
}
28 projects • 12 followers
I've been interested in microprocessors for a long time.
Comments
Please log in or sign up to comment.