Je cherche à créer un horodateur qui allume une lampe de 7h30 à 18h30 et j'utilise un module grove RTC DS1307. J'utilise la librairie RTClib.h
#include "RTClib.h"
#include "rgb_lcd.h"
#include <Wire.h>
RTC_DS1307 RTC;
rgb_lcd lcd;
int Lampe = 3;
void setup () {
Serial.begin(57600);
lcd.begin(16,2);
lcd.setRGB(50,25,50);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(2019, 1, 21, 14, 40, 0));
}
pinMode(Lampe, OUTPUT);
}
void loop() {
Heure();
Eclairage();
}
void Heure () {
DateTime now = RTC.now();
lcd.setCursor(0,0);
lcd.print("Date: ");
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(' ');
lcd.setCursor(0,1);
lcd.print("Heure: ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.println();
delay(1000);
}
void Eclairage()
{
if (RTC.now() >DateTime(2019, 1, 21, 8, 30, 0))
{
analogWrite(Lampe, HIGH);
}
else if (RTC.now() < DateTime(2019, 1, 21, 18, 30, 0))
{
analogWrite(Lampe, LOW);
}
}
Merci d'avance