//#include <MD_MAX72XX.h>
#include <MD_Parola.h>
#include <SPI.h>
#include <MD_MAX72xx.h>
// Define hardware type and number of devices
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
// Define pins
#define DATA_PIN 11
#define CLK_PIN 13
#define CS_PIN 10
// Create a matrix display object
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
int hour = 10;
int minute = 10;
int second = 0;
// Function prototypes
void drawClockFace();
void updateClockHands(int h, int m, int s);
void incrementTime();
void setup() {
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, 8);
mx.clear();
drawClockFace();
updateClockHands(hour, minute, second);
}
void loop() {
delay(1000); // Update every second
incrementTime();
drawClockFace();
updateClockHands(hour, minute, second);
}
void drawClockFace() {
mx.clear();
// Draw hour markers
for (int i = 0; i < 12; i++) {
float angle = i * 30 * PI / 180;
int x = 16 + 7 * cos(angle - PI / 2);
int y = 8 + 7 * sin(angle - PI / 2);
mx.setPoint(y, x, true);
}
}
void updateClockHands(int h, int m, int s) {
// Calculate angles for each hand
float angle_s = s * 6 * PI / 180;
float angle_m = (m + s / 60.0) * 6 * PI / 180;
float angle_h = (h % 12 + m / 60.0) * 30 * PI / 180;
// Draw second hand
int x_s = 16 + 7 * cos(angle_s - PI / 2);
int y_s = 8 + 7 * sin(angle_s - PI / 2);
mx.setPoint(y_s, x_s, true);
// Draw minute hand
int x_m = 16 + 5 * cos(angle_m - PI / 2);
int y_m = 8 + 5 * sin(angle_m - PI / 2);
mx.setPoint(y_m, x_m, true);
// Draw hour hand
int x_h = 16 + 3 * cos(angle_h - PI / 2);
int y_h = 8 + 3 * sin(angle_h - PI / 2);
mx.setPoint(y_h, x_h, true);
}
void incrementTime() {
second++;
if (second == 60) {
second = 0;
minute++;
if (minute == 60) {
minute = 0;
hour++;
if (hour == 24) {
hour = 0;
}
}
}
}