Using data from DS1307 RTC to trigger event
hi
i attemting build led clock acts analog clock except without hands. i have set several shift registers drive leds around clock face. part working fine having trouble getting data rtc , using trigger next led turn on.
for example second want 1 more led turn on. to want use second output of rtc , compare pre stored rtc second value , if different turn on next led. is best way approach this? or maybe put in interrupt sets flag high every time second value rtc changes?
here code using data rtc. it works fine, can set time , view time/date on serial connection.
here code using proof of concept @ moment. it controls 8 shift registers connected 64 leds. it steps through each 1 lighting them in sequence. it using delay() function 1 second delay. i rtc instead.
this first post please bear me. thanks
i attemting build led clock acts analog clock except without hands. i have set several shift registers drive leds around clock face. part working fine having trouble getting data rtc , using trigger next led turn on.
for example second want 1 more led turn on. to want use second output of rtc , compare pre stored rtc second value , if different turn on next led. is best way approach this? or maybe put in interrupt sets flag high every time second value rtc changes?
here code using data rtc. it works fine, can set time , view time/date on serial connection.
code: [select]
// date , time functions using ds1307 rtc connected via i2c , wire lib
#include <wire.h>
#include "rtclib.h"
rtc_ds1307 rtc;
void setup () {
serial.begin(57600);
wire.begin();
rtc.begin();
if (! rtc.isrunning()) {
serial.println("rtc not running!");
// following line sets rtc date & time sketch compiled
rtc.adjust(datetime(__date__, __time__));
}
}
void loop () {
datetime = rtc.now();
serial.print(now.year(), dec);
serial.print('/');
serial.print(now.month(), dec);
serial.print('/');
serial.print(now.day(), dec);
serial.print(' ');
serial.print(now.hour(), dec);
serial.print(':');
serial.print(now.minute(), dec);
serial.print(':');
serial.print(now.second(), dec);
serial.println();
delay(1000);
}here code using proof of concept @ moment. it controls 8 shift registers connected 64 leds. it steps through each 1 lighting them in sequence. it using delay() function 1 second delay. i rtc instead.
code: [select]
//pin definitions
// 7hc595n has 3 pins
int data = 11; // send bits control outputs
int clock = 12; // keeps data in sync
int latch = 8; // tells shift register when activate output sequence
byte numbers[10] = {b00000000,b00000001,b00000011,b00000111,b00001111,b00011111,b00111111,b01111111,b11111111};
byte one = b00000001;
byte two = b00000011;
byte 3 = b00000111;
byte four = b00001111;
byte five = b00011111;
byte six = b00111111;
byte 7 = b01111111;
byte 8 = b11111111;
byte nine = b00000111;
byte blank = b00000000;
int flag = 0;
int time = 1000; // delay between each led step i.e. 1 second
int timezero = 0; // sets delay 0 changing between blocks of code each shift register smooth
int timesave = 1000; //resets time actual value of delay between each step. i.e. 1 second
void setup()
{
// set 3 control pins output
pinmode(data, output);
pinmode(clock, output);
pinmode(latch, output);
}
void loop(){
for(int i=flag;i<=8;i++){
digitalwrite (latch, low);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, numbers[i]);
digitalwrite (latch, high);
if(i==8){
time=timezero;
}
delay(time);
}
time=timesave;
for(int i=0;i<=8;i++){
digitalwrite (latch, low);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, numbers[i]);
shiftout (data, clock, msbfirst, eight);
digitalwrite (latch, high);
if(i==8){
time=timezero;
}
delay(time);
time=timesave;
}
for(int i=0;i<=8;i++){
digitalwrite (latch, low);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, numbers[i]);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
digitalwrite (latch, high);
if(i==8){
time=timezero;
flag = 1;
}
delay(time);
}
time=timesave;
for(int i=0;i<=8;i++){
digitalwrite (latch, low);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, numbers[i]);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
digitalwrite (latch, high);
if(i==8){
time=timezero;
flag = 1;
}
delay(time);
}
time=timesave;
for(int i=0;i<=8;i++){
digitalwrite (latch, low);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, numbers[i]);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
digitalwrite (latch, high);
if(i==8){
time=timezero;
flag = 1;
}
delay(time);
}
time=timesave;
for(int i=0;i<=8;i++){
digitalwrite (latch, low);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, numbers[i]);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
digitalwrite (latch, high);
if(i==8){
time=timezero;
flag = 1;
}
delay(time);
}
time=timesave;
for(int i=0;i<=8;i++){
digitalwrite (latch, low);
shiftout (data, clock, msbfirst, blank);
shiftout (data, clock, msbfirst, numbers[i]);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
digitalwrite (latch, high);
if(i==8){
time=timezero;
flag = 1;
}
delay(time);
}
time=timesave;
for(int i=0;i<=9;i++){
digitalwrite (latch, low);
shiftout (data, clock, msbfirst, numbers[i]);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
shiftout (data, clock, msbfirst, eight);
digitalwrite (latch, high);
if(i==9){
time=timezero;
flag = 1;
}
delay(time);
}
time=timesave;
this first post please bear me. thanks
quote
to want use second output of rtc , compare pre stored rtc second value , if different turn on next led.
and change stored value.
quote
is best way approach this?
it's relatively simple way. other update display based on "now" every pass through loop.
quote
or maybe put in interrupt sets flag high every time second value rtc changes?
what else arduino doing, needs interrupted? there is, far know, no way rtc generate interrupt when second value changes.
Arduino Forum > Using Arduino > Programming Questions > Using data from DS1307 RTC to trigger event
arduino
Comments
Post a Comment