mirror of
https://github.com/filiprojek/auto-awning-close.git
synced 2024-11-23 01:31:02 +01:00
Temporary version: rain and wind actions disabled
This commit is contained in:
parent
ef05ce16e0
commit
fa60386901
432
main/main.ino
432
main/main.ino
@ -1,216 +1,216 @@
|
|||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Rtc_Pcf8563.h>
|
#include <Rtc_Pcf8563.h>
|
||||||
|
|
||||||
RCSwitch mySwitch = RCSwitch();
|
RCSwitch mySwitch = RCSwitch();
|
||||||
Rtc_Pcf8563 rtc;
|
Rtc_Pcf8563 rtc;
|
||||||
|
|
||||||
// defining used pins
|
// defining used pins
|
||||||
int wind = 8;
|
int wind = 8;
|
||||||
int rain = 12;
|
int rain = 12;
|
||||||
int receiver = 9;
|
int receiver = 9;
|
||||||
|
|
||||||
int relay1 = 7;
|
int relay1 = 4;
|
||||||
int relay2 = 6;
|
int relay2 = 6;
|
||||||
int relay3 = 5;
|
int relay3 = 5;
|
||||||
int relay4 = 4;
|
int relay4 = 7;
|
||||||
|
|
||||||
// codes from remote controller
|
// codes from remote controller
|
||||||
const int recRelay4 = 3696136;
|
const int recRelay4 = 3696136;
|
||||||
const int recRelay3 = 16736114;
|
const int recRelay3 = 16736114;
|
||||||
const int recRelay2 = 16736120;
|
const int recRelay2 = 16736120;
|
||||||
const int recRelay1 = 16736113;
|
const int recRelay1 = 16736113;
|
||||||
|
|
||||||
int delayTime = 500;
|
int delayTime = 500;
|
||||||
// status of roleta
|
// status of roleta
|
||||||
bool isOpen = false;
|
bool isOpen = false;
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
pinMode(relay1, OUTPUT);
|
pinMode(relay1, OUTPUT);
|
||||||
pinMode(relay2, OUTPUT);
|
pinMode(relay2, OUTPUT);
|
||||||
pinMode(relay3, OUTPUT);
|
pinMode(relay3, OUTPUT);
|
||||||
pinMode(relay4, OUTPUT);
|
pinMode(relay4, OUTPUT);
|
||||||
pinMode(wind, INPUT);
|
pinMode(wind, INPUT);
|
||||||
pinMode(rain, INPUT);
|
pinMode(rain, INPUT);
|
||||||
|
|
||||||
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
|
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
|
||||||
|
|
||||||
//clear out the registers
|
//clear out the registers
|
||||||
///rtc.initClock();
|
///rtc.initClock();
|
||||||
//set a time to start with.
|
//set a time to start with.
|
||||||
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
||||||
///rtc.setDate(18, 6, 6, 0, 21);
|
///rtc.setDate(18, 6, 6, 0, 21);
|
||||||
//hr, min, sec
|
//hr, min, sec
|
||||||
///rtc.setTime(18, 44, 0);
|
///rtc.setTime(18, 44, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRTC()
|
void updateRTC()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
function to update RTC time using user input
|
function to update RTC time using user input
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ask user to enter new date and time
|
// ask user to enter new date and time
|
||||||
const char txt[6][15] = { "year [4-digit]", "month [1~12]", "day [1~31]",
|
const char txt[6][15] = { "year [4-digit]", "month [1~12]", "day [1~31]",
|
||||||
"hours [0~23]", "minutes [0~59]", "seconds [0~59]"};
|
"hours [0~23]", "minutes [0~59]", "seconds [0~59]"};
|
||||||
String str = "";
|
String str = "";
|
||||||
long newDate[6];
|
long newDate[6];
|
||||||
|
|
||||||
while (Serial.available()) {
|
while (Serial.available()) {
|
||||||
Serial.read(); // clear serial buffer
|
Serial.read(); // clear serial buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
|
|
||||||
Serial.print("Enter ");
|
Serial.print("Enter ");
|
||||||
Serial.print(txt[i]);
|
Serial.print(txt[i]);
|
||||||
Serial.print(": ");
|
Serial.print(": ");
|
||||||
|
|
||||||
while (!Serial.available()) {
|
while (!Serial.available()) {
|
||||||
; // wait for user input
|
; // wait for user input
|
||||||
}
|
}
|
||||||
|
|
||||||
str = Serial.readString(); // read user input
|
str = Serial.readString(); // read user input
|
||||||
newDate[i] = str.toInt(); // convert user input to number and save to array
|
newDate[i] = str.toInt(); // convert user input to number and save to array
|
||||||
|
|
||||||
Serial.println(newDate[i]); // show user input
|
Serial.println(newDate[i]); // show user input
|
||||||
}
|
}
|
||||||
|
|
||||||
// update RTC
|
// update RTC
|
||||||
//rtc.adjust(DateTime(2021, newDate[1], newDate[2], newDate[3], newDate[4], newDate[5]));
|
//rtc.adjust(DateTime(2021, newDate[1], newDate[2], newDate[3], newDate[4], newDate[5]));
|
||||||
rtc.setDate(newDate[2], 6, newDate[1], 0, 2020);
|
rtc.setDate(newDate[2], 6, newDate[1], 0, 2020);
|
||||||
Serial.println("RTC Updated!");
|
Serial.println("RTC Updated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void relayOn(int pin, bool controller = false)
|
void relayOn(int pin, bool controller = false)
|
||||||
{
|
{
|
||||||
Serial.print("realy ");
|
Serial.print("realy ");
|
||||||
Serial.print(pin);
|
Serial.print(pin);
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
if(controller == false)
|
if(controller == false)
|
||||||
{
|
{
|
||||||
Serial.println("jsemtu");
|
Serial.println("jsemtu");
|
||||||
if(pin == relay4)
|
if(pin == relay4)
|
||||||
{
|
{
|
||||||
isOpen = true;
|
isOpen = true;
|
||||||
}
|
}
|
||||||
if(pin == relay1)
|
if(pin == relay1)
|
||||||
{
|
{
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(pin, HIGH);
|
digitalWrite(pin, HIGH);
|
||||||
delay(delayTime);
|
delay(delayTime);
|
||||||
if(pin == relay3) {
|
if(pin == relay3) {
|
||||||
// delay(1500);
|
// delay(1500);
|
||||||
}
|
}
|
||||||
digitalWrite(pin, LOW);
|
digitalWrite(pin, LOW);
|
||||||
|
|
||||||
delay(delayTime);
|
delay(delayTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
//formatted strings are at the current time/date.
|
//formatted strings are at the current time/date.
|
||||||
Serial.print(rtc.formatTime());
|
Serial.print(rtc.formatTime());
|
||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
Serial.print(rtc.formatDate());
|
Serial.print(rtc.formatDate());
|
||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
// assign day and month into variable
|
// assign day and month into variable
|
||||||
char h1 = rtc.formatTime(RTCC_TIME_HM)[0];
|
char h1 = rtc.formatTime(RTCC_TIME_HM)[0];
|
||||||
char h2 = rtc.formatTime(RTCC_TIME_HM)[1];
|
char h2 = rtc.formatTime(RTCC_TIME_HM)[1];
|
||||||
int onlyHour = ( 10 * (h1 - '0') ) + h2 - '0';
|
int onlyHour = ( 10 * (h1 - '0') ) + h2 - '0';
|
||||||
|
|
||||||
char m1 = rtc.formatTime(RTCC_TIME_HM)[3];
|
char m1 = rtc.formatTime(RTCC_TIME_HM)[3];
|
||||||
char m2 = rtc.formatTime(RTCC_TIME_HM)[4];
|
char m2 = rtc.formatTime(RTCC_TIME_HM)[4];
|
||||||
int onlyMinutes = ( 10 * (m1 - '0') ) + m2 - '0';
|
int onlyMinutes = ( 10 * (m1 - '0') ) + m2 - '0';
|
||||||
|
|
||||||
char M1 = rtc.formatDate()[0];
|
char M1 = rtc.formatDate()[0];
|
||||||
char M2 = rtc.formatDate()[1];
|
char M2 = rtc.formatDate()[1];
|
||||||
int onlyMonth = ( 10 * (M1 - '0') ) + M2 - '0';
|
int onlyMonth = ( 10 * (M1 - '0') ) + M2 - '0';
|
||||||
|
|
||||||
Serial.println(onlyHour);
|
Serial.println(onlyHour);
|
||||||
Serial.println(onlyMinutes);
|
Serial.println(onlyMinutes);
|
||||||
Serial.println(onlyMonth);
|
Serial.println(onlyMonth);
|
||||||
Serial.println(isOpen);
|
Serial.println(isOpen);
|
||||||
|
|
||||||
// setting up date and time from serial monitor
|
// setting up date and time from serial monitor
|
||||||
if (Serial.available())
|
if (Serial.available())
|
||||||
{
|
{
|
||||||
char input = Serial.read();
|
char input = Serial.read();
|
||||||
if (input == 'u') updateRTC(); // update RTC time
|
if (input == 'u') updateRTC(); // update RTC time
|
||||||
}
|
}
|
||||||
|
|
||||||
// time actions
|
// time actions
|
||||||
if(onlyMonth >= 5 && onlyMonth <= 8)
|
if(onlyMonth >= 5 && onlyMonth <= 8)
|
||||||
{
|
{
|
||||||
if(onlyHour >= 7 && onlyHour <= 14)
|
if(onlyHour >= 7 && onlyHour <= 14)
|
||||||
{
|
{
|
||||||
if(isOpen == false)
|
if(isOpen == false)
|
||||||
{
|
{
|
||||||
Serial.println("cas otevira");
|
Serial.println("cas otevira");
|
||||||
relayOn(relay4);
|
relayOn(relay4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(isOpen == true)
|
if(isOpen == true)
|
||||||
{
|
{
|
||||||
Serial.println("cas zavira");
|
Serial.println("cas zavira");
|
||||||
relayOn(relay1);
|
relayOn(relay1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rain actions
|
// rain actions
|
||||||
if(digitalRead(rain) != HIGH)
|
if(digitalRead(rain) != HIGH)
|
||||||
{
|
{
|
||||||
Serial.println("voda zavira");
|
Serial.println("voda zavira");
|
||||||
relayOn(relay1, true);
|
//relayOn(relay1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// wind actions
|
// wind actions
|
||||||
if (digitalRead(wind) == HIGH)
|
if (digitalRead(wind) == HIGH)
|
||||||
{
|
{
|
||||||
Serial.println("vitr zavira");
|
Serial.println("vitr zavira");
|
||||||
//relayOn(relay1, true);
|
//relayOn(relay1, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//digitalWrite(relay1, LOW); -> probably useless
|
//digitalWrite(relay1, LOW); -> probably useless
|
||||||
}
|
}
|
||||||
|
|
||||||
// remote controller actions
|
// remote controller actions
|
||||||
if (mySwitch.available())
|
if (mySwitch.available())
|
||||||
{
|
{
|
||||||
int received = mySwitch.getReceivedValue();
|
int received = mySwitch.getReceivedValue();
|
||||||
Serial.println("Received " + received);
|
Serial.println("Received " + received);
|
||||||
|
|
||||||
if (received == recRelay1)
|
if (received == recRelay1)
|
||||||
{
|
{
|
||||||
relayOn(relay1, true);
|
relayOn(relay1, true);
|
||||||
}
|
}
|
||||||
if (received == recRelay2)
|
if (received == recRelay2)
|
||||||
{
|
{
|
||||||
relayOn(relay2, true);
|
relayOn(relay2, true);
|
||||||
}
|
}
|
||||||
if (received == recRelay3)
|
if (received == recRelay3)
|
||||||
{
|
{
|
||||||
relayOn(relay3, true);
|
relayOn(relay3, true);
|
||||||
}
|
}
|
||||||
if (received == recRelay4)
|
if (received == recRelay4)
|
||||||
{
|
{
|
||||||
relayOn(relay4, true);
|
relayOn(relay4, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
mySwitch.resetAvailable();
|
mySwitch.resetAvailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user