I search for timealarm library but I think in my case could be better to use a script as the following one.
In the future I need to modify light on /off in different manners that are not satisfied by timealarms.
I compiled the following script that work. I used very close timing for light on and off just to do some test.
at the first light on it works well, but then the light off is not respected and LEDs start to fade without a clear control.
could you help me to know what's wrong?
thank you
#include <Wire.h>
#include "Chronodot.h"
Chronodot RTC;
void setup () {
Serial.begin(9600);
Serial.println("Initializing Chronodot.");
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(2013,10,21,10,30,00)); // IMPORTANT ADJUST YOUR TIME BEFORE STARTING!!!!
}
void loop () {
DateTime now = RTC.now();
int ledPin = 9;
Serial.print(now.year(), DEC);
Serial.print('/');
if(now.month() < 10) Serial.print("0");
Serial.print(now.month(), DEC);
Serial.print('/');
if(now.day() < 10) Serial.print("0");
Serial.print(now.day(), DEC);
Serial.print(' ');
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();
Serial.print(now.tempC(), 1);
Serial.println(" degrees Celcius");
Serial.print(now.tempF(), DEC);
Serial.println(" degrees Farenheit");
Serial.println();
delay(5000); //the time and temperature is writed on serial port every 5 seconds
if ((now.hour() >= 10 && now.minute() >= 31 && now.second() >= 0)) {
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(ledPin, fadeValue);
delay(500); // just for example
}
}
if ((now.hour() >= 10 && now.minute() >= 35 && now.second() >= 0)) {
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
analogWrite(ledPin, fadeValue);
delay(500); // just for example
}
}
}