From 04e227cc7091f1f78434791fa280d3f545c4ef80 Mon Sep 17 00:00:00 2001 From: zlaxy Date: Sun, 12 Nov 2017 11:42:50 +0300 Subject: [PATCH] winter version --- twobuttonstimer.ino | 110 +++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/twobuttonstimer.ino b/twobuttonstimer.ino index 6333939..b8fdd9a 100644 --- a/twobuttonstimer.ino +++ b/twobuttonstimer.ino @@ -1,84 +1,80 @@ -/* - * based on: - * TimeRTC.pde - * example code illustrating Time library with Real Time Clock. - * +/* 2 relay-buttons on timer scetch + * [WINTER short time version] + * based on TimeRTC.pde + * Use SetTime scetch (from DS1307RTC library) for time-sync */ #include #include -#include // a basic DS1307 library that returns time as a time_t +#include // a basic DS1307 library that returns time as a time_t +int stopButton = 8; +int startButton = 9; int led = 13; int indicator = 0; -void setup() { - pinMode(8, OUTPUT); - pinMode(9, OUTPUT); +void setup() { + pinMode(stopButton, OUTPUT); + pinMode(startButton, OUTPUT); pinMode(led, OUTPUT); Serial.begin(9600); - while (!Serial) ; // wait until Arduino Serial Monitor opens - setSyncProvider(RTC.get); // the function to get the time from the RTC + while (!Serial); // wait until Arduino Serial Monitor opens + setSyncProvider(RTC.get); // the function to get the time from the RTC if(timeStatus()!= timeSet) - Serial.println("Unable to sync with the RTC"); + Serial.println("Unable to sync with the RTC"); else - Serial.println("RTC has set the system time"); + Serial.println("RTC has set the system time"); } -void loop() -{ +void loop() { if (timeStatus() == timeSet) { checkTime(); - } else { - // fast blinking indicate that time is not set or RTC is not plugged + } else { // fast blinking after boot indicates that time is not set or DS1307RTC is not plugged int i; - for (i = 1; i <= 50; i++) - { - digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) - delay(50); // wait for a second - digitalWrite(led, LOW); // turn the LED off by making the voltage LOW - delay(50); // wait for a second + for (i = 1; i <= 100; i++) { + digitalWrite(led, LOW); + delay(50); + digitalWrite(led, HIGH); + delay(50); } } - delay(1000); + delay(5000); } -void checkTime(){ - if ((hour()==6 || hour()==7 ) && (indicator==0)) { - pressSTART(); - } - if ((hour()==8) && (minute()==1)) { - pressSTOP(); - } - if ((hour()==12 || hour()==13 ) && (indicator==0)) { - pressSTART(); - } - if ((hour()==14) && (minute()==1)) { - pressSTOP(); - } - if ((hour()==17) && (indicator==0)) { - pressSTART(); - } - if ((hour()==18) && (minute()==25)) { - pressSTOP(); - } +// 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(); } -void pressSTOP(){ +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 +} + +void pressStop() { + delay(5000); digitalWrite(led, LOW); // turn the LED off by making the voltage LOW indicator = 0; - digitalWrite(8, HIGH); - delay(500); - digitalWrite(8, LOW); - delay(61000); -} - -void pressSTART(){ - digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) - indicator = 1; - digitalWrite(9, HIGH); - delay(500); - digitalWrite(9, LOW); - delay(61000); + digitalWrite(stopButton, HIGH); + delay(887); + digitalWrite(stopButton, LOW); + delay(61000); // wait a minute }