WordClock-Program to display time in words on WS2812B-LED-Stripe. With DS3231 RTC
Dependencies: PixelArray WordClock_de ds3231 mbed
Fork of mbed_ws2812b by
WordClock
Yet another wordclock...
Program for displaying time in (german) words on WS2812B LED-Matrix. Uses DS3231 RTC .
More fotos see:
https://photos.app.goo.gl/mSN6G145IdupbKv13
Diff: main.cpp
- Revision:
- 7:10b0f6ee5047
- Parent:
- 4:ed0ac1dd6ae4
--- a/main.cpp Sun Nov 05 20:36:48 2017 +0000 +++ b/main.cpp Mon Nov 06 20:47:56 2017 +0000 @@ -22,10 +22,46 @@ #include "WordClock.h" #include "ds3231.h" +/** add simple DST info to nvram of ds3231 +* we abuse bit RS1(bit3) from control-register which normally controls frequency of output-pin +*/ +class Ds3231_dst : public Ds3231 +{ +public: + Ds3231_dst(PinName sda, PinName scl) : Ds3231(sda,scl) {} -// brigtness beween 0 and 1.0 -#define BRIGHTNESS 0.5 - +/** set_DST(bool dst) +*/ + uint16_t set_DST(bool dst) { + ds3231_cntl_stat_t data = {0xAA, 0xAA}; + uint16_t rtn_val; + // first read CR + rtn_val = get_cntl_stat_reg(&data); + // applay dst + if (dst) { + data.control |= 1<<3; + } else { + data.control &= ~(1<<3); + } + //write back + rtn_val = set_cntl_stat_reg(data); + return 0; + } +/** bool get_DST() +*/ + bool get_DST() { + ds3231_cntl_stat_t data = {0xAA, 0xAA}; + uint16_t rtn_val; + // first read CR + rtn_val = get_cntl_stat_reg(&data); + // get dst + if (data.control & (1<<3)) { + return true; + } else { + return false; + } + } +}; int main() { @@ -34,25 +70,81 @@ WordClock clock(p5); //RTC with DS3231 : sda, scl - Ds3231 rtc(p9, p10); + Ds3231_dst rtc(p9, p10); Timer timer; + + //DaylightSavingTIme? + bool DST = false; + //Serial pc(USBTX, USBRX); // tx, rx { + //pc.baud(115200); + //pc.printf("\n\rconnected to mbed - WordClock...\n\r"); + // set time and date //time and calendar variables - ds3231_time_t time = {0, 47, 20, 0, 0}; //sec, min, hour, am/pm(1=pm), mode(1=12h) - ds3231_calendar_t calendar = {7, 5, 11, 2017}; //day(1=mon), date, month, year + ds3231_time_t time = {0, 39, 21, 0, 0}; //sec, min, hour, am/pm(1=pm), mode(1=12h) + ds3231_calendar_t calendar = {1, 6, 11, 17}; //day(1=mon), date, month, year(2 digits) uint16_t rtn_val; // only set RTC when required! - //rtn_val = rtc.set_time(time); - //rtn_val = rtc.set_calendar(calendar); +// rtn_val = rtc.set_time(time); +// rtn_val = rtc.set_calendar(calendar); +// rtn_val = rtc.set_DST(false); + + // initial display + + // show Winterzeit/Sommerzeit as stored in RTC + if (rtc.get_DST()){ + // SZ for Sommerzeit + clock.sz(); + DST = true; + }else{ + //WZ for Winterzeit + clock.wz(); + DST = false; + } + wait(2); + + while (1) { //display loop + + //read time + rtn_val = rtc.get_time(&time); + //pc.printf("%2d:%2d ",time.hours,time.minutes); + + // read date + rtn_val = rtc.get_calendar(&calendar); + //pc.printf("%2d.%2d.%2d - day:%d \n\r",calendar.date, calendar.month,calendar.year, calendar.day); + - while (1) { - //read time an show on LED - rtn_val = rtc.get_time(&time); + // check for DST time change + // only valid for europe!!! + // see http://www.instructables.com/id/The-Arduino-and-Daylight-Saving-Time-Europe/ + + //switch to ~DST on last sunday in october + if (calendar.day == 7 && calendar.month == 10 && calendar.date >= 25 && time.hours == 3 && DST==true){ + time.hours=2; + DST=false; + rtc.set_time(time); + rtc.set_DST(DST); + //show WZ + clock.wz(); + wait(2); + } + //switch to DST on last sunday in march + if (calendar.day == 7 && calendar.month == 3 && calendar.date >= 25 && time.hours == 2 && DST==false){ + time.hours=3; + DST=true; + rtc.set_time(time); + rtc.set_DST(DST); + //show SZ + clock.sz(); + wait(2); + } + + //display time clock.display_time(time.hours,time.minutes,time.seconds); - wait_ms(10); + wait_ms(100); } //testprograms from here on @@ -63,7 +155,7 @@ // time fast forward for (int h=0; h<=23; h++) { for (int m=0; m<=59; m++) { - for (int s=0;s<=59;s++){ + for (int s=0; s<=59; s++) { clock.display_time(h,m,s); wait_ms(5); }