#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <RTClib.h>
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4
#define DATA_PIN 11
#define CLK_PIN 13
#define CS_PIN 10
MD_Parola display(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
RTC_DS1307 rtc;
// ===== BUFFER =====
char line1[20];
char line2[10];
char line3[30];
bool blink = false;
unsigned long lastUpdate = 0;
const char* hari[] = {
"MINGGU","SENIN","SELASA","RABU",
"KAMIS","JUMAT","SABTU"
};
const char* bulan[] = {
"","JAN","FEB","MAR","APR","MEI","JUN",
"JUL","AGS","SEP","OKT","NOV","DES"
};
// ================= SETUP =================
void setup() {
display.begin();
display.setFont(nullptr); // FONT KECIL STABIL
display.setIntensity(6);
display.displayClear();
rtc.begin();
if (!rtc.isrunning()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
// ================= LOOP =================
void loop() {
display.displayAnimate();
if (millis() - lastUpdate >= 500) {
lastUpdate = millis();
showHMI();
}
}
// ================= HMI DISPLAY =================
void showHMI() {
DateTime now = rtc.now();
blink = !blink;
// ===== BARIS 1: JAM BESAR =====
sprintf(line1, "%02d:%02d", now.hour(), now.minute());
// ===== BARIS 2: DETIK KECIL =====
sprintf(line2, "%c%02d", blink ? ':' : ' ', now.second());
// ===== BARIS 3: TANGGAL + HARI =====
sprintf(line3, "%s %02d %s",
hari[now.dayOfTheWeek()],
now.day(),
bulan[now.month()]);
// ===== DISPLAY 1: JAM =====
display.displayText(
line1,
PA_CENTER,
0,
0,
PA_PRINT,
PA_NO_EFFECT
);
delay(50);
// ===== DISPLAY 2: DETIK =====
display.displayText(
line2,
PA_RIGHT,
0,
0,
PA_PRINT,
PA_NO_EFFECT
);
delay(50);
// ===== DISPLAY 3: TANGGAL =====
display.displayText(
line3,
PA_CENTER,
0,
0,
PA_PRINT,
PA_NO_EFFECT
);
}