add monthly timetable

This commit is contained in:
ivan 2018-05-12 19:39:53 +03:00
parent 0c228f2c28
commit d89cb1a202
2 changed files with 146 additions and 74 deletions

Binary file not shown.

View File

@ -8,9 +8,8 @@
#include <DS1307RTC.h> #include <DS1307RTC.h>
#include <SevenSegmentExtended.h> // Extended TM1637 library https://github.com/bremme/arduino-tm1637 #include <SevenSegmentExtended.h> // Extended TM1637 library https://github.com/bremme/arduino-tm1637
long maxOpenDoorVar = 8765; // Interval for maximum door opening time long maxOpenDoorVar = 8667; // Interval for maximum door opening time
// long openDoorVar = 3750; // Interval for door opening long closeDoorVar = 3667; // Interval for door closing
long closeDoorVar = 3999; // Interval for door closing
const byte redButton = 4; // RedButton: light on, open door const byte redButton = 4; // RedButton: light on, open door
const byte blackButton = 5; // BlackButton: light off, close door const byte blackButton = 5; // BlackButton: light off, close door
@ -21,11 +20,7 @@ const byte pinRelay4 = 9; // Motor relay control
const byte PIN_CLK = 10; // Define CLK pin (for 4-Digit Display) const byte PIN_CLK = 10; // Define CLK pin (for 4-Digit Display)
const byte PIN_DIO = 11; // Define DIO pin (for 4-Digit Display) const byte PIN_DIO = 11; // Define DIO pin (for 4-Digit Display)
const byte doorSwitch = 12; // Door's magnetically operated sealed switch const byte doorSwitch = 12; // Door's magnetically operated sealed switch
// const byte led = 13;
SevenSegmentExtended display(PIN_CLK, PIN_DIO);
// long ledPulse = 1000; // Interval for LED blinking pulse
long buttonCheck = 200; // Interval for checking button state long buttonCheck = 200; // Interval for checking button state
byte buttonCommand = 0; // Variable for buttons value: 0 - nothing, 1 - light on, 2 - light off byte buttonCommand = 0; // Variable for buttons value: 0 - nothing, 1 - light on, 2 - light off
byte displayWork = 0; // Variable for display status: 0 - nothing, 1 - work byte displayWork = 0; // Variable for display status: 0 - nothing, 1 - work
@ -36,9 +31,10 @@ long buttonShortPress = 600; // Interval for short press button action
unsigned long lastButtonPressed; unsigned long lastButtonPressed;
SevenSegmentExtended display(PIN_CLK, PIN_DIO);
// Threads: // Threads:
Thread pressButtonThread = Thread(); // Create thread for button state checking Thread pressButtonThread = Thread(); // Create thread for button state checking
// Thread ledThread = Thread(); // Create thread for LED pulse indication
void setup() { void setup() {
Serial.begin(9600); // Initializes the Serial connection @ 9600 baud for debug Serial.begin(9600); // Initializes the Serial connection @ 9600 baud for debug
@ -51,7 +47,6 @@ void setup() {
pinMode(pinRelay4, OUTPUT); pinMode(pinRelay4, OUTPUT);
pinMode(pinDC, OUTPUT); pinMode(pinDC, OUTPUT);
pinMode(pinLight, OUTPUT); pinMode(pinLight, OUTPUT);
// pinMode(led, OUTPUT);
pinMode(redButton, INPUT); pinMode(redButton, INPUT);
pinMode(blackButton, INPUT); pinMode(blackButton, INPUT);
pinMode(doorSwitch, INPUT); pinMode(doorSwitch, INPUT);
@ -67,9 +62,6 @@ void setup() {
else else
Serial.println("RTC has set the system time"); Serial.println("RTC has set the system time");
// LED blinking thread:
// ledThread.onRun(ledBlink);
// ledThread.setInterval(ledPulse); // Interval for LED blinking
// Button state cheking thread: // Button state cheking thread:
pressButtonThread.onRun(pressButton); pressButtonThread.onRun(pressButton);
pressButtonThread.setInterval(buttonCheck); // Interval for checking button pressing pressButtonThread.setInterval(buttonCheck); // Interval for checking button pressing
@ -81,8 +73,6 @@ void setup() {
void loop() { void loop() {
// Threads init: // Threads init:
// if (ledThread.shouldRun())
// ledThread.run();
if (pressButtonThread.shouldRun()) if (pressButtonThread.shouldRun())
pressButtonThread.run(); pressButtonThread.run();
@ -92,27 +82,7 @@ void loop() {
display.on(); display.on();
display.print("SET TIME"); display.print("SET TIME");
} }
/*
} else { // Fast blinking indicates that time is
int i; // not set or DS1307RTC is not plugged
for (i = 1; i <= 500; i++) {
digitalWrite(led, LOW);
delay(50);
digitalWrite(led, HIGH);
delay(50);
} }
}
*/
}
/*
// LED pulse blinking thread
void ledBlink() {
static bool ledStatus = false; // LED status bool
ledStatus = !ledStatus; // Invert LED state
digitalWrite(led, ledStatus); // Activate LED state
}
*/
// Check button pressing thread // Check button pressing thread
void pressButton() { void pressButton() {
@ -122,8 +92,6 @@ void pressButton() {
displayWork = 0; displayWork = 0;
} }
if (digitalRead(redButton) == HIGH || digitalRead(blackButton) == HIGH) { if (digitalRead(redButton) == HIGH || digitalRead(blackButton) == HIGH) {
// if (digitalRead(redButton) == HIGH) serStr("Red button pressed, time showed");
// if (digitalRead(blackButton) == HIGH) serStr("Black button pressed, time showed");
display.on(); display.on();
displayWork = 1; displayWork = 1;
display.printTime(hour(), minute(), true); display.printTime(hour(), minute(), true);
@ -244,48 +212,129 @@ void serStr(const char* serString) {
} }
void checkTime() { void checkTime() {
// Winter // January 08:06 08:50 16:27 17:11
// 6:56 open door, 7:01 light on, 10:01 light off, if (month() == 1) {
// 16:01 light on, 19:01 light off, 19:05 close door if (hour() == 8 && minute() == 15) {
if (month()==11 || month()==12 || month()==1 ) {
if (hour() == 6 && minute() == 56) {
openDoor(); openDoor();
delay(60000); delay(60000);
} }
if (hour() == 7 && minute() == 1) { if (hour() == 15 && minute() == 55) {
lightOn(); lightOn();
delay(60000); delay(60000);
} }
if (hour() == 10 && minute() == 1) { if (hour() == 17 && minute() == 35) {
lightOff(); lightOff();
delay(60000); delay(60000);
} }
if (hour() == 16 && minute() == 1) { if (hour() == 17 && minute() == 50) {
lightOn();
delay(60000);
}
if (hour() == 19 && minute() == 1) {
lightOff();
delay(60000);
}
if (hour() == 19 && minute() == 5) {
closeDoor(); closeDoor();
delay(60000); delay(60000);
} }
} }
// February 07:18 07:56 17:31 18:10
// Spring if (month() == 2) {
// 6:30 door open, 17:01 light on, 20:01 light off, 20:05 door close if (hour() == 7 && minute() == 20) {
if (month()==2 || month()==3 || month()==4 ) {
if (hour() == 6 && minute() == 30) {
openDoor(); openDoor();
delay(40000); delay(60000);
} }
if (hour() == 17 && minute() == 1) { if (hour() == 16 && minute() == 55) {
lightOn(); lightOn();
delay(60000); delay(60000);
} }
if (hour() == 20 && minute() == 1) { if (hour() == 18 && minute() == 30) {
lightOff();
delay(60000);
}
if (hour() == 18 && minute() == 45) {
closeDoor();
delay(60000);
}
}
// March 06:11 06:47 18:30 19:07
if (month() == 3) {
if (hour() == 6 && minute() == 15) {
openDoor();
delay(60000);
}
if (hour() == 17 && minute() == 55) {
lightOn();
delay(60000);
}
if (hour() == 19 && minute() == 30) {
lightOff();
delay(60000);
}
if (hour() == 19 && minute() == 45) {
closeDoor();
delay(60000);
}
}
// April 04:48 05:27 19:33 20:13
if (month() == 4) {
if (hour() == 4 && minute() == 55) {
openDoor();
delay(60000);
}
if (hour() == 20 && minute() == 50) {
closeDoor();
delay(60000);
}
}
// May 03:31 04:20 20:32 21:21
if (month() == 5) {
if (hour() == 3 && minute() == 50) {
openDoor();
delay(60000);
}
if (hour() == 21 && minute() == 55) {
closeDoor();
delay(60000);
}
}
// June 02:43 03:44 21:15 22:16
if (month() == 6) {
if (hour() == 3 && minute() == 15) {
openDoor();
delay(60000);
}
if (hour() == 22 && minute() == 50) {
closeDoor();
delay(60000);
}
}
// July 03:08 04:04 21:05 22:00
if (month() == 7) {
if (hour() == 3 && minute() == 30) {
openDoor();
delay(60000);
}
if (hour() == 22 && minute() == 35) {
closeDoor();
delay(60000);
}
}
// August 04:15 04:58 20:08 20:51
if (month() == 8) {
if (hour() == 4 && minute() == 15) {
openDoor();
delay(60000);
}
if (hour() == 21 && minute() == 30) {
closeDoor();
delay(60000);
}
}
// September 05:21 05:58 18:50 19:27
if (month() == 9) {
if (hour() == 5 && minute() == 25) {
openDoor();
delay(60000);
}
if (hour() == 18 && minute() == 20) {
lightOn();
delay(60000);
}
if (hour() == 19 && minute() == 50) {
lightOff(); lightOff();
delay(60000); delay(60000);
} }
@ -294,36 +343,59 @@ void checkTime() {
delay(60000); delay(60000);
} }
} }
// October 06:20 06:57 17:32 18:09
// Summer if (month() == 10) {
// 5:30 open door, 22:05 close door if (hour() == 6 && minute() == 25) {
if (month()==5 || month()==6 || month()==7 ) {
if (hour() == 5 && minute() == 30) {
openDoor(); openDoor();
delay(60000); delay(60000);
} }
if (hour() == 22 && minute() == 5) { if (hour() == 16 && minute() == 55) {
closeDoor();
delay(60000);
}
}
// Autumn
// 6:01 open door, 17:01 light on, 20:01 light off, 21:05 close door
if (month()==8 || month()==9 || month()==10 ) {
if (hour() == 6 && minute() == 1) {
openDoor();
delay(60000);
}
if (hour() == 17 && minute() == 1) {
lightOn(); lightOn();
delay(60000); delay(60000);
} }
if (hour() == 20 && minute() == 1) { if (hour() == 18 && minute() == 30) {
lightOff(); lightOff();
delay(60000); delay(60000);
} }
if (hour() == 21 && minute() == 5) { if (hour() == 18 && minute() == 45) {
closeDoor();
delay(60000);
}
}
// November 07:20 08:02 16:24 17:06
if (month() == 11) {
if (hour() == 7 && minute() == 30) {
openDoor();
delay(60000);
}
if (hour() == 15 && minute() == 55) {
lightOn();
delay(60000);
}
if (hour() == 17 && minute() == 30) {
lightOff();
delay(60000);
}
if (hour() == 17 && minute() == 45) {
closeDoor();
delay(60000);
}
}
// December 08:05 08:51 15:56 16:42
if (month() == 12) {
if (hour() == 8 && minute() == 20) {
openDoor();
delay(60000);
}
if (hour() == 15 && minute() == 25) {
lightOn();
delay(60000);
}
if (hour() == 17 && minute() == 5) {
lightOff();
delay(60000);
}
if (hour() == 17 && minute() == 25) {
closeDoor(); closeDoor();
delay(60000); delay(60000);
} }