#include <Wire.h>
#include <RTClib.h>
#include <DHT.h>
#include <MD_MAX72xx.h>
#include <MD_Parola.h>
// Define the type of display used
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4
// Connections for the MAX7219
#define CLK_PIN 18
#define DATA_PIN 16
#define CS_PIN 5
// Initialize RTC, DHT, and LED matrix display
RTC_DS1307 rtc;
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
MD_Parola display = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
//char[12][5]={"Jan","Feb","March","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec"};
// Variables to control the blinking colon
bool showColon = true; // Starts with colon shown
unsigned long previousMillis = 0;
const long interval = 1000; // Blink interval in milliseconds
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // Initialize I2C with specific SDA and SCL pins in (SDA, SCL)
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// Set the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
dht.begin();
display.begin();
display.setIntensity(0); // Set the brightness of the display (0-15)
display.displayClear();
}
void loop() {
DateTime now = rtc.now();
int temp = dht.readTemperature();
// Get the day of the week
int dayOfWeek = now.dayOfTheWeek(); // Returns 0 for Sunday, 1 for Monday, ..., 6 for Saturday
// Convert to day names
const char* dayNames[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char* dayName = dayNames[dayOfWeek];
//Display time in HH:MM format
char timeString[12];
int hour = now.hour() % 12;
if (hour == 0)
hour = 12; // handle midnight and noon cases
display.setTextAlignment(PA_CENTER);
for(int i=0;i<=50;i++)
{
if(i%2==0)
{
snprintf(timeString, sizeof(timeString), "%02d:%02d", hour, now.minute());
display.print(timeString);
delay(500);
}
else
{
snprintf(timeString, sizeof(timeString), "%02d %02d", hour, now.minute());
display.print(timeString);
delay(500);
}
}
display.displayClear();
while (!display.displayAnimate()) delay(25);
// Display Time in 12-hour format with AM/PM
snprintf(timeString, sizeof(timeString), "%02d:%02d %s", hour, now.minute(), now.hour() >= 12 ? "PM" : "AM");
display.displayText(timeString, PA_CENTER, 40, 1, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
while (!display.displayAnimate()) delay(25); // Continue animation
// Display Day Name
display.displayText(dayName, PA_CENTER, 40, 1, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
while (!display.displayAnimate()) delay(25); // Continue animation
const char* months[]={"Jan","Feb","March","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec"};
// Display Date in DD/MM/YYYY format
char dateString[25];
snprintf(dateString, sizeof(dateString), "%02d-%s-%04d", now.day(), months[now.month()], now.year());
display.displayText(dateString, PA_CENTER, 40, 1, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
while (!display.displayAnimate()) delay(25); // Continue animation
// Display Temperature in Celsius
const char deg=248;
char tempString[10];
dtostrf(temp, 1,1, tempString);
//strcat(tempString, (char)248);
strcat(tempString, "°C");
//snprintf(tempString, sizeof(tempString), "%.1f%cC", temp, 248); // 248 is the ASCII code for degree symbol
display.displayText(tempString, PA_CENTER, 40, 1, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
while (!display.displayAnimate()) delay(25); // Continue animation
}