//introduction bibliothèque RTClib
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
//tableau qui stocke les jours de la semaine + date + heure
String daysOfTheWeek[7] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
String leMoisElegant;
String leJourElegant;
String lHeureElegante;
String laMinuteElegante;
String laSecondeElegante;
//modules RTC (Real Time Clock) basés sur le circuit intégré DS1307
RTC_DS1307 rtc;
void setup () {
Serial.begin(115200); //vitesse de communication 115200 bauds
if (! rtc.begin()) { //si le module n'est pas reconnu =>message d'erreur
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
//fonction permettant le calcul de l'heure, date, ... grâce au module rtc + ajout "0" devant un nombre à 1 chiffre
void loop () {
DateTime now = rtc.now();
lcd.begin(20, 4);
if (now.month() < 10) {
leMoisElegant = "0" + String(now.month());
}
if (now.month() >= 10) {
leMoisElegant = String(now.month());
}
if (now.day() < 10) {
leJourElegant = "0" + String(now.day());
}
if (now.day() >= 10) {
leJourElegant = String(now.day());
}
if (now.hour() < 10) {
lHeureElegante = "0" + String(now.hour());
}
if (now.hour() >= 10) {
lHeureElegante = String(now.hour());
}
if (now.minute() < 10) {
laMinuteElegante = "0" + String(now.minute());
}
if (now.minute() >= 10) {
laMinuteElegante = String(now.minute());
}
if (now.second() < 10) {
laSecondeElegante = "0" + String(now.second());
}
if (now.second() >= 10) {
laSecondeElegante = String(now.second());
}
// collage des données en un texte
Serial.print("heure actuelle: ");
String temps = String(now.year()) + "/" + leMoisElegant + "/" + leJourElegant + String(" (" + daysOfTheWeek[now.dayOfTheWeek()]) + ") " + lHeureElegante + ":" + laMinuteElegante + ":" + laSecondeElegante;
lcd.print(temps);
//délais avant recalcul de l'heure
Serial.println(temps);
delay(1000);
}