#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Wire.h>
#include "RTClib.h"
#define TFT_CS 53
#define TFT_DC 9
#define TFT_RST 7
volatile bool analogClock = false;
volatile bool buttonPressed = false;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
RTC_DS1307 rtc; // create an instance of the RTC_DS1307 class
volatile int interruptCounter; // variable to store the number of timer interrupts
const int interruptInterval = 1000; // interval for timer interrupts in milliseconds
void setup() {
Serial.begin(9600); // initialize serial communication at 9600 bits per second
tft.begin(); // Initialize TFT display
tft.setRotation(0); // Set display rotation (if needed)
tft.fillScreen(ILI9341_BLACK); // Fill screen with black color
tft.setTextColor(ILI9341_YELLOW);
Wire.begin(); // initialize I2C communication
rtc.begin(); // initialize RTC communication
if (!rtc.isrunning()) { // check if RTC is running
Serial.println("RTC is NOT running!"); // display error message if RTC is not running
}
else {
Serial.println("RTC is running.");
}
// set up timer interrupt
noInterrupts(); // disable interrupts
TCCR1A = 0; // set TCCR1A register to 0
TCCR1B = 0; // set TCCR1B register to 0
TCNT1 = 0; // set TCNT1 register to 0
OCR1A = 15624; // set OCR1A register to match interruptInterval
TCCR1B |= (1 << WGM12); // set WGM12 bit for CTC mode
TCCR1B |= (1 << CS12) | (1 << CS10); // set prescaler to 1024
TIMSK1 |= (1 << OCIE1A); // enable timer interrupt
interrupts(); // enable interrupts
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK); // White on black
tft.setTextSize(3); // large letters
tft.setRotation(0); // horizontal display
}
ISR(TIMER1_COMPA_vect) {
interruptCounter++; // increment interrupt counter
}
void loop() {
// DateTime now = rtc.now(); // get current time from RTC
// Serial.print(now.hour(), DEC); // display hours
// Serial.print(':');
// Serial.print(now.minute(), DEC); // display minutes
// Serial.print(':');
// Serial.print(now.second(), DEC); // display seconds
// Serial.println();
// delay(1000); // delay for 1 second
tft.setCursor(0, tft.height()/2-60);
DateTime now = rtc.now();
tft.println("Current time: ");
tft.print(now.year(), DEC);
tft.print('/');
tft.print(now.month(), DEC);
tft.print('/');
tft.print(now.day(), DEC);
tft.print('\n');
tft.print('\n');
tft.println(daysOfTheWeek[now.dayOfTheWeek()]);
tft.print('\n');
if(now.hour()<10){
tft.print("0");
}
tft.print(now.hour(), DEC);
tft.print(':');
if(now.minute()<10){
tft.print("0");
}
tft.print(now.minute(), DEC);
tft.print(':');
if(now.second()<10){
tft.print("0");
}
tft.print(now.second(), DEC);
}