Hi!
It seems i make some mistake writing.... nevermind
I have a strange problem with alarm code.
After 20 or so times my alarm stop working from unknown reason...
Can anybody have some idea?
here is the code:
#include <Wire.h>
#include "RTClib.h"
#include <Time.h>
#include <TimeAlarms.h>
RTC_DS1307 rtc;
time_t syncProvider() //sinhro vremena, funkcija radi isto što i RTC_DS1307::get()
{
return rtc.now().unixtime();
}
int led = 13;
void setup()
{
Serial.begin(9600);
Serial.println("One timer is triggered every 15 seconds");
Serial.println();
pinMode(led, OUTPUT);
rtc.begin();
setSyncProvider(syncProvider);
Alarm.timerRepeat(15, RepeatTask);
}
void loop()
{
digitalClockDisplay();
Alarm.delay(1000);
}
void RepeatTask()
{
Serial.println("15 second timer");
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
delay(1000); // wait for a second
Did you miss the part about needing to replace ALL calls to delay() with calls to Alarm.delay() instead?
It seems I miss that part.... ![]()
Thanx very much... working now......
Here is another problem...
The RepeatTask (15 sec) alarm working fine but MorningAlarm wont't work at all
I checked several times but I see nothing wrong?
Any Idea?
Code:
#include <Wire.h>
#include "RTClib.h"
#include <Time.h>
#include <TimeAlarms.h>
RTC_DS1307 RTC;
int led = 13;
void setup(){
Serial.begin(57600);
Serial.println("One timer is triggered every 15 seconds");
Serial.println("The timer is triggered once a day");
Serial.println();
pinMode(led, OUTPUT);
Wire.begin();
RTC.begin();
if (!RTC.begin()) {
Serial.println("RTC failed");
while(1);
}
Alarm.alarmRepeat(9,9,00, MorningAlarm); // change time
Alarm.timerRepeat(15, RepeatTask);
}
void loop(){
//DateTime now = RTC.now();
digitalClockDisplay();
Alarm.delay(1000);
}
void RepeatTask()
{
Serial.println("15 second timer");
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
Alarm.delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
Alarm.delay(1000);
}
void MorningAlarm()
{
Serial.println("Single timer");
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
Alarm.delay(2000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
Alarm.delay(1000);
}
void digitalClockDisplay()
{
DateTime now = RTC.now(); // digital clock display of the time
if(now.hour()< 10)Serial.print("0");
Serial.print(now.hour(),DEC);
Serial.print(":");
if(now.minute ()< 10)Serial.print("0");
Serial.print(now.minute(),DEC);
Serial.print(":");
if(now.second ()< 10)Serial.print("0");
Serial.print(now.second(),DEC);
Serial.println();
}