heloo, first i am sorry ifmy english is bad.
i have project using arduino uno with esp8266 and blynk for controling relay with timer in each relay, i using menu widget for chose from relay 1-4 and after that, i can set timer in each relay and if timer is active, then will triger led widget to turn on, but i new in arduino but i know little bit. First i use blynk_write(), but this can’t use multiple input vPin, so can i use blynk_write_default() for using multiple vpin??
for clearly this my code for set timer menu :
BLYNK_WRITE_DEFAULT() {
int vPin = request.pin;
if (vPin == 9){
switch(param.asInt())
{
case 1:
if (EEPROM.read(7)==0) { Blynk.virtualWrite(V11,0); led1.on(); }
else { Blynk.virtualWrite(V11,1); led1.off(); }
if (vPin == 11) {
if (param.asInt()==0) {
led1.on();EEPROM.write(7, 0);
TimeInputParam t(param);
EEPROM.write(13,t.getStartHour());
EEPROM.write(14,t.getStartMinute());
EEPROM.write(15,t.getStopHour());
EEPROM.write(16,t.getStopMinute());
Serial.print(TR1a1);
Serial.println(TR1a2);
}
else {
led1.off();EEPROM.write(7, 1);
EEPROM.write(13,00);
EEPROM.write(14,00);
EEPROM.write(15,00);
EEPROM.write(16,00);
}
}
break;
case 2:
if (EEPROM.read(8)==0){Blynk.virtualWrite(V11,0); led2.on();}
else {Blynk.virtualWrite(V11,1); led2.off();}
if (vPin == 11) {
if (param.asInt()==0) {
led2.on();EEPROM.write(8, 0);
TimeInputParam t(param);
EEPROM.write(17,t.getStartHour());
EEPROM.write(18,t.getStartMinute());
EEPROM.write(19,t.getStopHour());
EEPROM.write(20,t.getStopMinute());
}
else {
led2.off();EEPROM.write(8, 1);
EEPROM.write(17,00);
EEPROM.write(18,00);
EEPROM.write(19,00);
EEPROM.write(20,00);;
}
}
break;
case 3:
if (EEPROM.read(9)==0){Blynk.virtualWrite(V11,0); led3.on();}
else {Blynk.virtualWrite(V11,1); led3.off();}
if (vPin == 11) {
if (param.asInt()==0) {
led3.on();EEPROM.write(9, 0);
TimeInputParam t(param);
EEPROM.write(21,t.getStartHour());
EEPROM.write(22,t.getStartMinute());
EEPROM.write(23,t.getStopHour());
EEPROM.write(24,t.getStopMinute());
}
else {
led3.off();EEPROM.write(9, 1);
EEPROM.write(21,00);
EEPROM.write(22,00);
EEPROM.write(23,00);
EEPROM.write(24,00);
}
}
break;
case 4:
if (EEPROM.read(10)==0){Blynk.virtualWrite(V11,0); led4.on();}
else {Blynk.virtualWrite(V11,1); led4.off();}
if (vPin == 11) {
if (param.asInt()==0) {
led4.on();EEPROM.write(10, 0);
TimeInputParam t(param);
EEPROM.write(25,t.getStartHour());
EEPROM.write(26,t.getStartMinute());
EEPROM.write(27,t.getStopHour());
EEPROM.write(28,t.getStopMinute());
}
else {
led4.off();EEPROM.write(10, 1);
EEPROM.write(25,00);
EEPROM.write(26,00);
EEPROM.write(27,00);
EEPROM.write(28,00);
}
}
break;
case 5:
if (EEPROM.read(11)==0){Blynk.virtualWrite(V11,0); led5.on();}
else {Blynk.virtualWrite(V11,1); led5.off();}
if (vPin == 11) {
if (param.asInt()==0) {
led5.on();EEPROM.write(11, 0);
TimeInputParam t(param);
EEPROM.write(29,t.getStartHour());
EEPROM.write(30,t.getStartMinute());
EEPROM.write(31,t.getStopHour());
EEPROM.write(32,t.getStopMinute());
}
else {
led5.off();EEPROM.write(11, 1);
EEPROM.write(29,00);
EEPROM.write(30,00);
EEPROM.write(31,00);
EEPROM.write(32,00);
}
}
break;
case 6:
if (EEPROM.read(11)==0){Blynk.virtualWrite(V11,0); led6.on();}
else {Blynk.virtualWrite(V11,1); led6.off();}
if (vPin == 11) {
if (param.asInt()==0) {
led6.on();EEPROM.write(12, 0);
TimeInputParam t(param);
EEPROM.write(33,t.getStartHour());
EEPROM.write(34,t.getStartMinute());
EEPROM.write(35,t.getStopHour());
EEPROM.write(36,t.getStopMinute());
}
else {
led6.off();EEPROM.write(12, 1);
EEPROM.write(33,00);
EEPROM.write(34,00);
EEPROM.write(35,00);
EEPROM.write(36,00);
}
}
break;
}
}
}
after upload to my hardware, this code not working and not give some feedback to my app, even just turn on led widget, so i think the problem is in my code.
and this is my code for triger the relay to turn on/off, sory if this code lot of false code (i am new in this) :
void TimerRelay(){
String RTC = rtc.getHour()+rtc.getMinute();
String R1on = TR1a1+TR1a2; String R1off = TR1b1+TR1b2; //tr1a1 for start hour, tr1a2 for start minute, tr1b1 for stophour
String R2on = TR2a1+TR2a2; String R2off = TR2b1+TR2b2;
String R3on = TR3a1+TR3a2; String R3off = TR3b1+TR3b2;
String R4on = TR4a1+TR4a2; String R4off = TR4b1+TR4b2;
String R5on = TR5a1+TR5a2; String R5off = TR5b1+TR5b2;
String R6on = TR6a1+TR6a2; String R6off = TR6b1+TR6b2;
if(EEPROM.read(7==0)){
if(RTC==R1on){digitalWrite(relay1, LOW);Serial.println("Relay 1 ON via Timer");
EEPROM.write(1, 0);}
if(RTC==R1off){digitalWrite(relay1, HIGH);Serial.println("Relay 1 OFF via Timer");
EEPROM.write(1, 1);}
}
if(EEPROM.read(8==0)){
if(RTC==R2on){digitalWrite(relay2, LOW);Serial.println("Relay 2 ON via Timer");
EEPROM.write(2, 0);}
if(RTC==R2off){digitalWrite(relay2, HIGH);Serial.println("Relay 2 OFF via Timer");
EEPROM.write(2, 1);}
}
if(EEPROM.read(9==0)){
if(RTC==R3on){digitalWrite(relay3, LOW);Serial.println("Relay 3 ON via Timer");
EEPROM.write(3, 0);}
if(RTC==R3off){digitalWrite(relay3, HIGH);Serial.println("Relay 3 OFF via Timer");
EEPROM.write(3, 1);}
}
if(EEPROM.read(10==0)){
if(RTC==R4on){digitalWrite(relay4, LOW);Serial.println("Relay 4 ON via Timer");
EEPROM.write(4, 0);}
if(RTC==R4off){digitalWrite(relay4, HIGH);Serial.println("Relay 4 OFF via Timer");
EEPROM.write(4, 1);}
}
if(EEPROM.read(11==0)){
if(RTC==R5on){digitalWrite(relay5, LOW);Serial.println("Relay 5 ON via Timer");
EEPROM.write(5, 0);}
if(RTC==R5off){digitalWrite(relay5, HIGH);Serial.println("Relay 5 OFF via Timer");
EEPROM.write(5, 1);}
}
if(EEPROM.read(12==0)){
if(RTC==R6on){digitalWrite(relay6, LOW);Serial.println("Relay 6 ON via Timer");
EEPROM.write(6, 0);}
if(RTC==R6off){digitalWrite(relay6, HIGH);Serial.println("Relay 6 OFF via Timer");
EEPROM.write(6, 1);}
}
}
maybe you can help me for fix this,
so thanks friend