Hi Guys,
so I got my clock working really nice with a RTC and everything. I'm also able to turn an alarm on and off. So far so good...
What I want to do is turn an alarm on at 4PM and turn it off at 5PM
setSyncProvider(RTC.get);
Alarm.delay(0);
Alarm.alarmRepeat(16,0,0, ledAlarmOn);
Alarm.delay(0);
Alarm.alarmRepeat(17,0,0, ledAlarmOff);
.
.
.
void ledAlarmOn(){
digitalWrite(Pin1, HIGH);
}
void ledAlarmOff(){
digitalWrite(Pin1, LOW);
BUT: What if I turn on my device at 4:30PM, I still want the alarm come on and stay on till 5PM.
That's my problem and I need help! Is there any if> function I could use or a totally different approach?
Thank you so much!!!
Flo
I'm sorry...here is the code I used:
setSyncProvider(RTC.get);
Alarm.delay(0);
Alarm.alarmRepeat(16,0,0, ledAlarmOn);
Alarm.delay(0);
Alarm.alarmRepeat(17,0,0, ledAlarmOff);
.
.
.
void ledAlarmOn(){
digitalWrite(Pin1, HIGH);
}
void ledAlarmOff(){
digitalWrite(Pin1, LOW);
Arrch
November 28, 2012, 10:42pm
4
daflogotit:
I'm sorry...here is the code I used:
Random periods are likely to cause a compiler error. Same with the lack of setup and loop functions.
system
November 28, 2012, 10:42pm
5
here is the code I used:
No setup() function, no loop() function, and those dots won't compile. That is NOT the code you used.
I didn't mean to mess up my very first post, I guess I just wanted to "shorten" my code to demonstrate what I'm talking about...
#include <Wire.h>
#include <DS1307RTC.h>
#include <Time.h>
#include <TimeAlarms.h>
int Pin1 = 7;
void setup()
{
Wire.begin();
Serial.begin(9600);
pinMode(Pin1, OUTPUT);
}
void loop()
{
setSyncProvider(RTC.get);
Alarm.delay(0);
Alarm.alarmRepeat(16,0,0, ledAlarmOn);
Alarm.delay(0);
Alarm.alarmRepeat(17,0,0, ledAlarmOff);
}
void ledAlarmOn(){
digitalWrite(Pin1, HIGH);
}
void ledAlarmOff(){
digitalWrite(Pin1, LOW);
}
I hope this is better
Arrch
November 28, 2012, 10:56pm
7
So you need to get the current time at start-up and check if it's within your alarm range. If so, run the ledAlarmOn() function.
system
November 28, 2012, 10:58pm
8
setSyncProvider(RTC.get);
Alarm.delay(0);
Alarm.alarmRepeat(16,0,0, ledAlarmOn);
Alarm.delay(0);
Alarm.alarmRepeat(17,0,0, ledAlarmOff);
None of this belongs in loop().
Hi Arrch, that's a great idea. I'm just not sure about a good way to do that...
I tried a couple things like
if functions in the
Alarm.delay(0);
Alarm.alarmRepeat(16,0,0, ledAlarmOn);
any ideas? Thanks
Arrch
November 28, 2012, 11:06pm
10
No idea what you are trying to do here:
if functions in the
Alarm.delay(0);
Alarm.alarmRepeat(16,0,0, ledAlarmOn);
but I would recommend looking into the RTC library for some kind of function that that returns the current time. Even better if you can return just the hour and compare it to 16. If it's equal, then run ledAlarmOn.
Great thanks, I'm going to try to find some