DCF RTC LCD klok
1 bericht
• Pagina 1 van 1
DCF RTC LCD klok
Nog een bouwsel! Nu wat extra componenten toegevoegd die de Arduino aanstuurd.
In dit project zijn (naast de Arduino nano) een RTC module met de DS3231 chip, een DCF77 ontvanger en een LCD gebruikt.
Op de RTC module heb ik de diode losgesoldeerd die naar de knoopcel gaat zodat er een gewone niet oplaadbare in past.
Ook is m'n 3D printer ingezet om de behuizing te maken.
Voor iets meer info en foto's zie mijn website (Weird Science Web)
In dit project zijn (naast de Arduino nano) een RTC module met de DS3231 chip, een DCF77 ontvanger en een LCD gebruikt.
Op de RTC module heb ik de diode losgesoldeerd die naar de knoopcel gaat zodat er een gewone niet oplaadbare in past.
Ook is m'n 3D printer ingezet om de behuizing te maken.
Voor iets meer info en foto's zie mijn website (Weird Science Web)
- Code: Alles selecteren
#include <DCF77.h>
#include <DS3231.h>
#include <LiquidCrystal.h>
#define DCF_PIN 2
#define DCF_INTERRUPT 0
#define SYNC_BUTTON_PIN 7 // Synchronize button with pull down resistor.
const char *weekDayName[] = { "Zon", "Maa", "Din", "Woe", "Don", "Vrij", "Zat" }; // In Dutch
const char *monthName[] = { "Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"}; // In Dutch
bool h12, PM, century = false;
DS3231 Clock;
DCF77 DCF = DCF77( DCF_PIN, DCF_INTERRUPT );
time_t DCFtime;
LiquidCrystal lcd( 12, 11, 6, 5, 4, 3 );
void setup()
{
lcd.begin( 16, 2 );
Wire.begin();
delay( 1000 );
pinMode( SYNC_BUTTON_PIN, INPUT );
// Start synchronizing when RTC is powered up for the very first time.
if( Clock.getDate() == 1 && Clock.getMonth( century ) == 1 && Clock.getYear() == 0 ) {
synchronizeDCF();
}
}
void loop()
{
// Start synchronizing every day at 3:00 AM or anytime when the synchronize button is pushed.
if(( Clock.getHour( h12, PM ) == 3 && Clock.getMinute() == 0 ) || digitalRead( SYNC_BUTTON_PIN ) == HIGH ) {
synchronizeDCF();
}
displayCRTTime();
delay( 190 ); // Delay for a swift display response but no need for faster
}
void synchronizeDCF()
{
int i, limit;
DCF.Start();
delay( 1000 );
limit = Clock.getMinute() - 1;
if( limit == -1 )
{
limit = 59;
}
do
{
for( i = 0; i < 10; i++ )
{
lcd.setCursor( 14, 0 );
lcd.print( !digitalRead( DCF_PIN ) ? char( 219 ) : char( 165 ) ); // Show the pulses from the DCF77 transmitter.
delay( 98 );
}
DCFtime = DCF.getTime(); // Gets the time through interrupt signals
displayCRTTime(); // Update display anyway, even if there isn't a current time available
} while( DCFtime == 0 && Clock.getMinute() != limit ); // try synchronizing for 59 minutes8
lcd.setCursor( 14, 0 );
if( DCFtime != 0 )
{
setTime( DCFtime );
setCRTTime();
lcd.print( " " );
}
else
{
lcd.print( "X" ); // Marker on the LCD to show that there was no synchronization possible
}
DCF.Stop();
}
void displayCRTTime() {
char buf[17];
sprintf( buf, "%2d:%02d:%02d", Clock.getHour( h12, PM ), Clock.getMinute(), Clock.getSecond() );
lcd.setCursor( 4, 0 );
lcd.print( buf );
sprintf( buf, "%-4s %2d %s 2%d%02d", weekDayName[Clock.getDoW() - 1], Clock.getDate(), monthName[Clock.getMonth( century ) - 1], century > 0 ? 1 : 0, Clock.getYear() );
lcd.setCursor( 0, 1 );
lcd.print( buf );
}
void setCRTTime()
{
Clock.setSecond( second() );
Clock.setMinute( minute() );
Clock.setHour( hour() );
Clock.setDoW( weekday() );
Clock.setDate( day() );
Clock.setMonth( month() );
Clock.setYear( year() - 2000 );
}
Advertisement
1 bericht
• Pagina 1 van 1
Terug naar Afgeronde projecten
Wie is er online?
Gebruikers in dit forum: Geen geregistreerde gebruikers en 2 gasten