|
#include <DS1302.h> |
|
#include <LCD4884.h> |
|
#include <LowPower.h> |
|
|
|
|
|
DS1302 rtc; |
|
LCD4884 lcd; |
|
|
|
const char *daysOfWeek[] = { |
|
"Dimanche", |
|
"Lundi", |
|
"Mardi", |
|
"Mercredi", |
|
"Jeudi", |
|
"Vendredi", |
|
"Samedi" |
|
}; |
|
|
|
|
|
void setup() |
|
{ |
|
Serial.begin(9600); |
|
|
|
// LCD initialization |
|
lcd.init(); |
|
|
|
/* |
|
RTC initialization (date setter) |
|
ONLY RUN THE FIRST TIME AND COMMENT IT OUT AFTERWARDS ! |
|
*/ |
|
//rtc.init(45, 6, 1, 2, 9, 1, 2018, H24); |
|
} |
|
|
|
|
|
void loop() |
|
{ |
|
// Let's fetch date and time on the DS1302 |
|
rtc.read(); |
|
|
|
// If it's possible we update the screen with the latest fetched values |
|
if(rtc.dateTime.Day >= 0 && rtc.dateTime.Day < 7) |
|
{ |
|
// Let's clear the screen at first |
|
lcd.clear(); |
|
|
|
// Don't turn backlight always on (Hey ! It's time to sleep a bit...) |
|
uint8_t hour = rtc.dateTime.h24.Hour10 * 10 + rtc.dateTime.h24.Hour; |
|
if(hour >= 8 && hour <= 21) |
|
{ |
|
lcd.turnBacklightOn(true); |
|
} |
|
|
|
// A buffer which will receive the data below successively |
|
char buffer[64]; |
|
|
|
// Displays the day of week |
|
sprintf(buffer, "%s", daysOfWeek[rtc.dateTime.Day]); |
|
lcd.writeString(CENTER(buffer), 1, buffer, MENU_NORMAL); |
|
|
|
// Displays the time |
|
sprintf(buffer, "%02d:%02d", |
|
bcd2bin(rtc.dateTime.h24.Hour10, rtc.dateTime.h24.Hour), |
|
bcd2bin(rtc.dateTime.Minutes10, rtc.dateTime.Minutes) |
|
); |
|
lcd.writeString(CENTER(buffer), 3, buffer, MENU_NORMAL); |
|
|
|
// Displays the date |
|
sprintf(buffer, "%02d/%02d/%d", |
|
bcd2bin(rtc.dateTime.Date10, rtc.dateTime.Date), |
|
bcd2bin(rtc.dateTime.Month10, rtc.dateTime.Month), |
|
2000 + bcd2bin(rtc.dateTime.Year10, rtc.dateTime.Year) |
|
); |
|
lcd.writeString(CENTER(buffer), 4, buffer, MENU_NORMAL); |
|
} |
|
|
|
// Let's idle for 4 seconds... |
|
LowPower.idle(SLEEP_4S, |
|
ADC_OFF, |
|
TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, |
|
SPI_OFF, USART0_OFF, TWI_OFF |
|
); |
|
|
|
// ... before turning off the screen backlight |
|
lcd.turnBacklightOn(false); |
|
|
|
// Now we wait the for maximum borned duration allowed by the `LowPower` library |
|
LowPower.idle(SLEEP_8S, |
|
ADC_OFF, |
|
TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, |
|
SPI_OFF, USART0_OFF, TWI_OFF |
|
); |
|
} |