/*
Arduino | coding-help
smaqlo — 11/24/24 at 4:16 PM
hey there I want to implement something in this circuit,
as you can see, the hours and minutes are showing correctly,
i want some of the LEDs on the last matrix to like toggle on/off
every second precisely
*/
//#include <Wire.h>
#include <RTClib.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW //FC16_HW // Type de matériel (matrices LED 1088AS)
#define MAX_DEVICES 4 // Nombre total de matrices chaînées
#define CS_PIN 10 // Broche CS pour le MAX7219
const unsigned long HALF_SECOND = 500;
unsigned long prevTime = 0;
bool indicator = false;
RTC_DS1307 rtc; // Initialisation du module RTC DS1307
MD_Parola display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
// Initialisation des matrices LED
display.begin();
display.setIntensity(3); // Réglage de la luminosité (0-15)
display.displayClear(); // Efface les matrices
// Initialisation du module RTC DS1307
if (!rtc.begin()) {
display.print("Erreur RTC");
while (1); // Blocage si le RTC n'est pas détecté
}
// Vérifier si le RTC est initialisé
if (!rtc.isrunning()) {
// Si le RTC n'est pas initialisé, régler l'heure à la date de compilation
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
if (millis() - prevTime >= HALF_SECOND) {
prevTime = millis();
indicator = !indicator;
// Lire l'heure actuelle
DateTime now = rtc.now();
// Formatage de l'heure au format HH:MM
char timeBuffer[6];
if (indicator) {
sprintf(timeBuffer, " %02d %02d", now.hour(), now.minute());
} else {
sprintf(timeBuffer, " %02d:%02d", now.hour(), now.minute());
}
// Afficher l'heure sur les matrices LED
display.print(timeBuffer);
}
//delay(1000); // Mise à jour toutes les secondes
}