BLYNK_WRITE(V10)//Up to you
{
if (automode == 1){
sprintf(Date, "%02d/%02d/%04d", day(), month(), year());
sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
TimeInputParam t(param);
terminal.print("Auto Mode Checked schedule at: ");
terminal.println(Time);
terminal.flush();
int dayadjustment = -1;
if (weekday() == 1) {
dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}
if (t.isWeekdaySelected(weekday() + dayadjustment)) { //Time library starts week on Sunday, Blynk on Monday
terminal.println("Auto Mode ACTIVE today");
terminal.flush();
if (t.hasStartTime()) // Process start time
{
terminal.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
terminal.flush();
}
if (t.hasStopTime()) // Process stop time
{
terminal.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute()+ ":" + t.getStopSecond());
terminal.flush();
}
// Display timezone details, for information purposes only
terminal.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time
terminal.println("At least ONE day MUST be selected");
//terminal.println(String("Time zone offset: ") + t.getTZ_Offset()); // Get timezone offset (in seconds)
terminal.flush();
for (int i = 1; i <= 7; i++) { // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
if (t.isWeekdaySelected(i)) {
terminal.println(String("Day ") + i + " is selected");
terminal.flush();
}
}
nowseconds = ((hour() * 3600) + (minute() * 60) + second());
startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60) + (t.getStartSecond());
Serial.println(startsecondswd); // used for debugging
if (nowseconds >= startsecondswd) {
terminal.print("Auto Mode STARTED at");
terminal.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute() + ":" + t.getStartSecond());
terminal.flush();
if (nowseconds <= startsecondswd) { // 90s on 60s timer ensures 1 trigger command is sent
if(digitalRead(relayLed)==HIGH){
if(TC == true){
digitalWrite(relayLed, LOW); // set LED ON
Blynk.virtualWrite(V2, 1);
led4.on();
TC = false;
}
// code here to switch the relay ON
}
}
}
else {
digitalWrite(relayLed, HIGH); // set LED OFF
Blynk.virtualWrite(V2, 0);
led4.off();
terminal.println("Auto Mode Device NOT STARTED today");
terminal.flush();
TC = true;
}
stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60) + (t.getStopSecond());
Serial.println(stopsecondswd); // used for debugging
if (nowseconds >= stopsecondswd) {
if(digitalRead(relayLed)==LOW){
if(TC == false){
digitalWrite(relayLed, HIGH); // set LED OFF
Blynk.virtualWrite(V2, 0);
led4.off();
terminal.print("Auto Mode STOPPED at");
terminal.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
terminal.flush();
TC = true;
}
}
}
/*if (nowseconds <= stopsecondswd + 90) { // 90s on 60s timer ensures 1 trigger command is sent
digitalWrite(relayLed, HIGH); // set LED OFF
Blynk.virtualWrite(V2, 0);
led4.off();
// code here to switch the relay OFF
}*/
else {
if (nowseconds >= startsecondswd) {
digitalWrite(relayLed, LOW); // set LED ON
Blynk.virtualWrite(V2, 1);
led4.on();
terminal.println("Auto Mode is ON");
terminal.flush();
TC = false;
}
}
}
}
else {
terminal.println("Auto Mode INACTIVE today");
terminal.flush();
// nothing to do today, check again in 30 SECONDS time
}
terminal.println();
}
BLYNK_WRITE(V16)//Up to you
{
if (automode2 == 1) {
sprintf(Date, "%02d/%02d/%04d", day(), month(), year());
sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
TimeInputParam t(param);
terminal.print("Auto Mode Checked schedule at: ");
terminal.println(Time);
terminal.flush();
int dayadjustment = -1;
if (weekday() == 1) {
dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}
if (t.isWeekdaySelected(weekday() + dayadjustment)) { //Time library starts week on Sunday, Blynk on Monday
terminal.println("Auto Mode ACTIVE today");
terminal.flush();
if (t.hasStartTime()) // Process start time
{
terminal.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
terminal.flush();
}
if (t.hasStopTime()) // Process stop time
{
terminal.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute()+ ":" + t.getStopSecond());
terminal.flush();
}
// Display timezone details, for information purposes only
terminal.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time
terminal.println("At least ONE day MUST be selected");
//terminal.println(String("Time zone offset: ") + t.getTZ_Offset()); // Get timezone offset (in seconds)
terminal.flush();
for (int i = 1; i <= 7; i++) { // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
if (t.isWeekdaySelected(i)) {
terminal.println(String("Day ") + i + " is selected");
terminal.flush();
}
}
nowseconds2 = ((hour() * 3600) + (minute() * 60) + second());
startsecondswd2 = (t.getStartHour() * 3600) + (t.getStartMinute() * 60) + (t.getStartSecond());
Serial.println(startsecondswd2); // used for debugging
if (nowseconds2 >= startsecondswd2) {
terminal.print("Auto Mode STARTED at");
terminal.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute() + ":" + t.getStartSecond());
terminal.flush();
if (nowseconds2 <= startsecondswd2) { // 90s on 60s timer ensures 1 trigger command is sent
if(digitalRead(relayLed)==HIGH){
if(TC2 == false){
digitalWrite(relayLed, LOW); // set LED ON
Blynk.virtualWrite(V2, 1);
led4.on();
TC2 = true;
// code here to switch the relay ON
}
}
}
}
else {
digitalWrite(relayLed, HIGH); // set LED OFF
Blynk.virtualWrite(V2, 0);
led4.off();
terminal.println("Auto Mode Device NOT STARTED today");
terminal.flush();
TC2 = false;
}
stopsecondswd2 = (t.getStopHour() * 3600) + (t.getStopMinute() * 60) + (t.getStopSecond());
Serial.println(stopsecondswd); // used for debugging
if (nowseconds2 >= stopsecondswd2) {
if(digitalRead(relayLed)==LOW){
if(TC2 == true){
digitalWrite(relayLed, HIGH); // set LED OFF
Blynk.virtualWrite(V2, 0);
led4.off();
terminal.print("Auto Mode STOPPED at");
terminal.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
terminal.flush();
TC2 = false;
/*if (nowseconds2 <= stopsecondswd2 + 90) { // 90s on 60s timer ensures 1 trigger command is sent
digitalWrite(relayLed, HIGH); // set LED OFF
Blynk.virtualWrite(V2, 0);
led4.off();
// code here to switch the relay OFF
}*/
}
}
}
else {
if (nowseconds2 >= startsecondswd2) {
digitalWrite(relayLed, LOW); // set LED ON
Blynk.virtualWrite(V2, 1);
terminal.println("Auto Mode is ON");
terminal.flush();
led4.on();
TC2 = true;
}
}
}
else {
terminal.println("Auto Mode INACTIVE today");
terminal.flush();
// nothing to do today, check again in 30 SECONDS time
}
terminal.println();
}
}
ผมใส่แล้วครับ ทั้งสอง Timer ตัวแรกยังกระพริบ ตัวสองก็กระพริบแต่น้อยครั้ง ไม่รู้ว่าวางถูกต้องมั้ย