3 various seasons schedule

This commit is contained in:
ivan 2018-05-13 18:27:29 +03:00
parent e5e0352111
commit dbc0e80c56
1 changed files with 24 additions and 48 deletions

View File

@ -1,6 +1,5 @@
// 2 relay-buttons on timer with 4-digit display
#include <Arduino.h>
#include <Wire.h>
#include <TimeLib.h>
#include <Thread.h>
#include <DS1307RTC.h> // A basic DS1307 library that returns time as a time_t
@ -12,18 +11,15 @@ const byte redButton = 4; // RedButton: light on, open door
const byte blackButton = 5; // BlackButton: light off, close door
const byte stopButtonRelay = 6;
const byte startButtonRelay = 7;
// const byte led = 13;
const int msStart = 639; // Interval for pressing start button, ms
const int msStop = 637; // Interval for pressing stop button, ms
const int msStart = 889; // Interval for pressing start button, ms
const int msStop = 887; // Interval for pressing stop button, ms
const int updateTime = 1000; // Interval for digit display update
const int buttonCheck = 200; // Interval for checking button state
const long manualButtonTime = 3600000; // 60 min - actual state of manual pressed button
long buttonMillis = 0; // Previous button press counter
byte indicator = 0; // Indicator of working states: 0 - scheduled off; 1 - scheduled on;
// 2 - manual off, 3 - manual on
SevenSegmentExtended display(PIN_CLK, PIN_DIO);
Thread showTimeThread = Thread(); // Create thread for LED pulse indication
Thread pressButtonThread = Thread(); // Create thread for button state checking
@ -37,7 +33,6 @@ void setup() {
pinMode(blackButton, INPUT);
pinMode(stopButtonRelay, OUTPUT);
pinMode(startButtonRelay, OUTPUT);
// pinMode(led, OUTPUT);
while (!Serial); // Wait until Arduino Serial Monitor opens
setSyncProvider(RTC.get); // The function to get the time from the RTC
if(timeStatus()!= timeSet)
@ -160,7 +155,7 @@ void pressButton() {
if (buttonMillis>0) {
if (indicator==3) {
if ((currentMillis-buttonMillis) > manualButtonTime) {
serStr("manualButtonTime expired...press stop");
serStr("manualButtonTime expired...stop pressed");
buttonMillis = 0;
pressStop();
}
@ -185,14 +180,13 @@ void pressButton() {
}
}
// Winter timing 6:00-7:31, 12:00-13:01, 17:00-18:01
void checkTime() {
// Winter
if (month()==12 || month()==1 || month()==2 ) {
// 6:00 - 7:01 - working
// 6:00 - 7:16 - working
if ((hour()==6) && (indicator==0)) pressStart();
// 7:01 - stop
if ((hour()==7) && (minute()==1)) pressStop();
if ((hour()==7) && (minute()==16)) pressStop();
// 12:00 - 13:01 - working
if ((hour()==12) && (indicator==0)) pressStart();
// 13:01 - stop
@ -203,51 +197,33 @@ void checkTime() {
if ((hour()==18) && (minute()==1)) pressStop();
}
// Spring & Autumn
/*
// ! TEMPORARY CHANGES !
if (month()==3 || month()==4 || month()==5 || month()==9 || month()==10 || month()==11) {
// 6:00 - 7:41 - working
if ((hour()==6) && (indicator==0)) pressStart();
// 7:41 - stop
if ((hour()==7) && (minute()==41)) pressStop();
// 12:00 - 13:01 - working
if (month()==3 || month()==4 || month()==10 || month()==11) {
// 6:00 - 8:21 - working
if ((hour()==6 || hour()==7) && (indicator==0)) pressStart();
// 8:21 - stop
if ((hour()==8) && (minute()==21)) pressStop();
// 12:00 - 13:26 - working
if ((hour()==12) && (indicator==0)) pressStart();
// 13:01 - stop
if ((hour()==13) && (minute()==1)) pressStop();
// 13:26 - stop
if ((hour()==13) && (minute()==26)) pressStop();
// 17:00 - 18:21 - working
if ((hour()==17) && (indicator==0)) pressStart();
// 18:21 - stop
if ((hour()==18) && (minute()==21)) pressStop();
}
*/
// ! TEMPORARY CHANGES !
if (month()==3 || month()==4 || month()==5 || month()==9 || month()==10 || month()==11) {
// 6:00 - 8:01 - working
if ((hour()==6 || hour()==7) && (indicator==0)) pressStart();
// 8:01 - stop
if ((hour()==8) && (minute()==1)) pressStop();
// 12:00 - 13:31 - working
if ((hour()==12) && (indicator==0)) pressStart();
// 13:31 - stop
if ((hour()==13) && (minute()==31)) pressStop();
// 17:00 - 18:41 - working
if ((hour()==17) && (indicator==0)) pressStart();
// 18:41 - stop
if ((hour()==18) && (minute()==41)) pressStop();
}
// Summer
if (month()==6 || month()==7 || month()==8 ) {
// 6:00 - 8:01 - working
if (month()==5 || month()==6 || month()==7 || month()==8 || month()==9) {
// 6:00 - 8:28 - working
if ((hour()==6 || hour()==7) && (indicator==0)) pressStart();
// 8:01 - stop
if ((hour()==8) && (minute()==1)) pressStop();
// 12:00 - 14:01 - working
// 8:23 - stop
if ((hour()==8) && (minute()==28)) pressStop();
// 12:00 - 14:11 - working
if ((hour()==12 || hour()==13) && (indicator==0)) pressStart();
// 14:01 - stop
if ((hour()==14) && (minute()==1)) pressStop();
// 17:00 - 18:25 - working
// 14:11 - stop
if ((hour()==14) && (minute()==11)) pressStop();
// 17:00 - 18:35 - working
if ((hour()==17) && (indicator==0)) pressStart();
// 18:25 - stop
if ((hour()==18) && (minute()==25)) pressStop();
// 18:35 - stop
if ((hour()==18) && (minute()==35)) pressStop();
}
}
}