winter version
This commit is contained in:
parent
636e9bdfa6
commit
04e227cc70
|
@ -1,20 +1,21 @@
|
||||||
/*
|
/* 2 relay-buttons on timer scetch
|
||||||
* based on:
|
* [WINTER short time version]
|
||||||
* TimeRTC.pde
|
* based on TimeRTC.pde
|
||||||
* example code illustrating Time library with Real Time Clock.
|
* Use SetTime scetch (from DS1307RTC library) for time-sync
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <TimeLib.h>
|
#include <TimeLib.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
|
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
|
||||||
|
|
||||||
|
int stopButton = 8;
|
||||||
|
int startButton = 9;
|
||||||
int led = 13;
|
int led = 13;
|
||||||
int indicator = 0;
|
int indicator = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(8, OUTPUT);
|
pinMode(stopButton, OUTPUT);
|
||||||
pinMode(9, OUTPUT);
|
pinMode(startButton, OUTPUT);
|
||||||
pinMode(led, OUTPUT);
|
pinMode(led, OUTPUT);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
while (!Serial); // wait until Arduino Serial Monitor opens
|
while (!Serial); // wait until Arduino Serial Monitor opens
|
||||||
|
@ -25,60 +26,55 @@ void setup() {
|
||||||
Serial.println("RTC has set the system time");
|
Serial.println("RTC has set the system time");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop() {
|
||||||
{
|
|
||||||
if (timeStatus() == timeSet) {
|
if (timeStatus() == timeSet) {
|
||||||
checkTime();
|
checkTime();
|
||||||
} else {
|
} else { // fast blinking after boot indicates that time is not set or DS1307RTC is not plugged
|
||||||
// fast blinking indicate that time is not set or RTC is not plugged
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i <= 50; i++)
|
for (i = 1; i <= 100; i++) {
|
||||||
{
|
digitalWrite(led, LOW);
|
||||||
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
|
delay(50);
|
||||||
delay(50); // wait for a second
|
digitalWrite(led, HIGH);
|
||||||
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
|
delay(50);
|
||||||
delay(50); // wait for a second
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(1000);
|
delay(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Winter timing 6:00-8:01, 12:00-13:01, 17:00-18:01
|
||||||
void checkTime() {
|
void checkTime() {
|
||||||
if ((hour()==6 || hour()==7 ) && (indicator==0)) {
|
// 6:00 - 8:01 - working
|
||||||
pressSTART();
|
if ((hour()==6) && (indicator==0)) pressStart();
|
||||||
}
|
if ((hour()==7) && (indicator==0)) pressStart();
|
||||||
if ((hour()==8) && (minute()==1)) {
|
// 8:01 - stop
|
||||||
pressSTOP();
|
if ((hour()==8) && (minute()==1)) pressStop();
|
||||||
}
|
// 12:00 - 13:01 - working
|
||||||
if ((hour()==12 || hour()==13 ) && (indicator==0)) {
|
if ((hour()==12) && (indicator==0)) pressStart();
|
||||||
pressSTART();
|
// 13:01 - stop
|
||||||
}
|
if ((hour()==13) && (minute()==1)) pressStop();
|
||||||
if ((hour()==14) && (minute()==1)) {
|
// 17:00 - 18:01 - working
|
||||||
pressSTOP();
|
if ((hour()==17) && (indicator==0)) pressStart();
|
||||||
}
|
// 18:01 - stop
|
||||||
if ((hour()==17) && (indicator==0)) {
|
if ((hour()==18) && (minute()==1)) pressStop();
|
||||||
pressSTART();
|
|
||||||
}
|
|
||||||
if ((hour()==18) && (minute()==25)) {
|
|
||||||
pressSTOP();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pressSTOP(){
|
void pressStart() {
|
||||||
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
|
delay(5000);
|
||||||
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)
|
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||||
indicator = 1;
|
indicator = 1;
|
||||||
digitalWrite(9, HIGH);
|
digitalWrite(startButton, HIGH);
|
||||||
delay(500);
|
delay(889);
|
||||||
digitalWrite(9, LOW);
|
digitalWrite(startButton, LOW);
|
||||||
delay(61000);
|
delay(61000); // wait a minute
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue