mirror of
https://github.com/filiprojek/auto-awning-close.git
synced 2024-11-22 17:31:02 +01:00
update
This commit is contained in:
parent
53239d2d58
commit
6c79e4d8e4
@ -1,9 +1,13 @@
|
|||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Rtc_Pcf8563.h>
|
||||||
|
|
||||||
RCSwitch mySwitch = RCSwitch();
|
RCSwitch mySwitch = RCSwitch();
|
||||||
|
Rtc_Pcf8563 rtc;
|
||||||
|
|
||||||
// defining used pins
|
// defining used pins
|
||||||
int wind = 8;
|
int wind = 8;
|
||||||
|
int rain = 12;
|
||||||
int receiver = 9;
|
int receiver = 9;
|
||||||
|
|
||||||
int relay1 = 7;
|
int relay1 = 7;
|
||||||
@ -28,8 +32,55 @@ void setup()
|
|||||||
pinMode(relay3, OUTPUT);
|
pinMode(relay3, OUTPUT);
|
||||||
pinMode(relay4, OUTPUT);
|
pinMode(relay4, OUTPUT);
|
||||||
pinMode(wind, INPUT);
|
pinMode(wind, 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
|
||||||
|
rtc.initClock();
|
||||||
|
//set a time to start with.
|
||||||
|
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
||||||
|
rtc.setDate(14, 6, 3, 1, 10);
|
||||||
|
//hr, min, sec
|
||||||
|
rtc.setTime(1, 15, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateRTC()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
function to update RTC time using user input
|
||||||
|
*/
|
||||||
|
|
||||||
|
// ask user to enter new date and time
|
||||||
|
const char txt[6][15] = { "year [4-digit]", "month [1~12]", "day [1~31]",
|
||||||
|
"hours [0~23]", "minutes [0~59]", "seconds [0~59]"};
|
||||||
|
String str = "";
|
||||||
|
long newDate[6];
|
||||||
|
|
||||||
|
while (Serial.available()) {
|
||||||
|
Serial.read(); // clear serial buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
|
||||||
|
Serial.print("Enter ");
|
||||||
|
Serial.print(txt[i]);
|
||||||
|
Serial.print(": ");
|
||||||
|
|
||||||
|
while (!Serial.available()) {
|
||||||
|
; // wait for user input
|
||||||
|
}
|
||||||
|
|
||||||
|
str = Serial.readString(); // read user input
|
||||||
|
newDate[i] = str.toInt(); // convert user input to number and save to array
|
||||||
|
|
||||||
|
Serial.println(newDate[i]); // show user input
|
||||||
|
}
|
||||||
|
|
||||||
|
// update RTC
|
||||||
|
//rtc.adjust(DateTime(2021, newDate[1], newDate[2], newDate[3], newDate[4], newDate[5]));
|
||||||
|
rtc.setDate(newDate[2], 6, newDate[1], 0, 2020);
|
||||||
|
Serial.println("RTC Updated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void relayOn(int pin)
|
void relayOn(int pin)
|
||||||
@ -43,8 +94,28 @@ void relayOn(int pin)
|
|||||||
delay(delayTime);
|
delay(delayTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
//formatted strings are at the current time/date.
|
||||||
|
Serial.print(rtc.formatTime());
|
||||||
|
Serial.print("\r\n");
|
||||||
|
Serial.print(rtc.formatDate());
|
||||||
|
Serial.print("\r\n");
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
if (Serial.available())
|
||||||
|
{
|
||||||
|
char input = Serial.read();
|
||||||
|
if (input == 'u') updateRTC(); // update RTC time
|
||||||
|
}
|
||||||
|
|
||||||
|
if(digitalRead(rain) != HIGH)
|
||||||
|
{
|
||||||
|
Serial.println("cegoslav");
|
||||||
|
}
|
||||||
|
|
||||||
// wind actions
|
// wind actions
|
||||||
if (digitalRead(wind) == HIGH)
|
if (digitalRead(wind) == HIGH)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user