Skip to content

Instantly share code, notes, and snippets.

@HorlogeSkynet
Created January 9, 2018 09:20
Show Gist options
  • Save HorlogeSkynet/7702ea9fd299edd6734c3cf14b7e07aa to your computer and use it in GitHub Desktop.
Save HorlogeSkynet/7702ea9fd299edd6734c3cf14b7e07aa to your computer and use it in GitHub Desktop.
A program to display the date on a LCD4884 shield fetched from a DS1302 RTC module

Alzheimer_Grand-Parents

A program to display the date on a LCD4884 shield fetched from a DS1302 RTC module on Arduino

This program has been made in order to display the day of week, for people losing all notion of time.
With the help of the LowPower library, its execution is supposed to consume very little energy.

How to use it ?

You need first to install these libraries into your Arduino IDE :

Then, fetch the source code present within this very Gist, and paste it under your IDE.

How does it differ from a regular weather station ?

It actually does not, but many weather stations display date in English, and some old persons unfortunately don't understand it.
This program allows you to choose the format for the date and the hour, and names for your week days.

#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
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment