2017-11-12 08:42:50 +00:00
|
|
|
/* 2 relay-buttons on timer scetch
|
|
|
|
* [WINTER short time version]
|
|
|
|
* based on TimeRTC.pde
|
|
|
|
* Use SetTime scetch (from DS1307RTC library) for time-sync
|
2017-07-26 11:23:09 +00:00
|
|
|
*/
|
|
|
|
|
2017-06-18 13:38:59 +00:00
|
|
|
#include <TimeLib.h>
|
2017-07-26 11:23:09 +00:00
|
|
|
#include <Wire.h>
|
2017-11-12 08:42:50 +00:00
|
|
|
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
|
2017-06-18 13:38:59 +00:00
|
|
|
|
2017-11-12 08:42:50 +00:00
|
|
|
int stopButton = 8;
|
|
|
|
int startButton = 9;
|
2017-07-26 11:23:09 +00:00
|
|
|
int led = 13;
|
|
|
|
int indicator = 0;
|
2017-06-18 13:38:59 +00:00
|
|
|
|
2017-11-12 08:42:50 +00:00
|
|
|
void setup() {
|
|
|
|
pinMode(stopButton, OUTPUT);
|
|
|
|
pinMode(startButton, OUTPUT);
|
2017-07-26 11:23:09 +00:00
|
|
|
pinMode(led, OUTPUT);
|
|
|
|
Serial.begin(9600);
|
2017-11-12 08:42:50 +00:00
|
|
|
while (!Serial); // wait until Arduino Serial Monitor opens
|
|
|
|
setSyncProvider(RTC.get); // the function to get the time from the RTC
|
2017-07-26 11:23:09 +00:00
|
|
|
if(timeStatus()!= timeSet)
|
2017-11-12 08:42:50 +00:00
|
|
|
Serial.println("Unable to sync with the RTC");
|
2017-07-26 11:23:09 +00:00
|
|
|
else
|
2017-11-12 08:42:50 +00:00
|
|
|
Serial.println("RTC has set the system time");
|
2017-06-18 13:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 08:42:50 +00:00
|
|
|
void loop() {
|
2017-06-18 13:38:59 +00:00
|
|
|
if (timeStatus() == timeSet) {
|
2017-07-26 11:23:09 +00:00
|
|
|
checkTime();
|
2017-11-12 08:42:50 +00:00
|
|
|
} else { // fast blinking after boot indicates that time is not set or DS1307RTC is not plugged
|
2017-07-26 11:23:09 +00:00
|
|
|
int i;
|
2017-11-12 08:42:50 +00:00
|
|
|
for (i = 1; i <= 100; i++) {
|
|
|
|
digitalWrite(led, LOW);
|
|
|
|
delay(50);
|
|
|
|
digitalWrite(led, HIGH);
|
|
|
|
delay(50);
|
2017-07-26 11:23:09 +00:00
|
|
|
}
|
2017-06-18 13:38:59 +00:00
|
|
|
}
|
2017-11-12 08:42:50 +00:00
|
|
|
delay(5000);
|
2017-06-18 13:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 08:42:50 +00:00
|
|
|
// Winter timing 6:00-8:01, 12:00-13:01, 17:00-18:01
|
|
|
|
void checkTime() {
|
|
|
|
// 6:00 - 8:01 - working
|
|
|
|
if ((hour()==6) && (indicator==0)) pressStart();
|
|
|
|
if ((hour()==7) && (indicator==0)) pressStart();
|
|
|
|
// 8:01 - stop
|
|
|
|
if ((hour()==8) && (minute()==1)) pressStop();
|
|
|
|
// 12:00 - 13:01 - working
|
|
|
|
if ((hour()==12) && (indicator==0)) pressStart();
|
|
|
|
// 13:01 - stop
|
|
|
|
if ((hour()==13) && (minute()==1)) pressStop();
|
|
|
|
// 17:00 - 18:01 - working
|
|
|
|
if ((hour()==17) && (indicator==0)) pressStart();
|
|
|
|
// 18:01 - stop
|
|
|
|
if ((hour()==18) && (minute()==1)) pressStop();
|
2017-06-18 13:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 08:42:50 +00:00
|
|
|
void pressStart() {
|
|
|
|
delay(5000);
|
|
|
|
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
|
|
|
|
indicator = 1;
|
|
|
|
digitalWrite(startButton, HIGH);
|
|
|
|
delay(889);
|
|
|
|
digitalWrite(startButton, LOW);
|
|
|
|
delay(61000); // wait a minute
|
2017-06-18 13:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 08:42:50 +00:00
|
|
|
void pressStop() {
|
|
|
|
delay(5000);
|
|
|
|
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
|
|
|
|
indicator = 0;
|
|
|
|
digitalWrite(stopButton, HIGH);
|
|
|
|
delay(887);
|
|
|
|
digitalWrite(stopButton, LOW);
|
|
|
|
delay(61000); // wait a minute
|
2017-06-18 13:38:59 +00:00
|
|
|
}
|
|
|
|
|