I'm using Blynk along with a WeMos D1 R2 and i can change modes through an ON/OFF button.
I can succesfully change mode and make my application go from mode 1 (irrigation) to mode 2 (Fertilization), but through the code i manage to switch from mode 2 to mode 1(after my code does what it is meant to do).
However, i cannot make the button show up as being in mode 1 again, if the application is working properly in mode 1. Any ideas on how to update button condition?
My code follows(below the code you can see the app and the button Using the V1 virtual pin):
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
Blynk.begin(auth, ssid, pass);
pinMode(Relay1, OUTPUT); // Setup Relay pin as output pin
pinMode(Relay2, OUTPUT); // Setup Relay pin as output pin
//pinMode(led_pin, OUTPUT);
pinMode(sensor_pin, INPUT);
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay1,HIGH);
digitalWrite(Relay2,HIGH);
}
BLYNK_READ(V8)
{
Blynk.virtualWrite(8,level); // virtualpin 8 distance
}
BLYNK_WRITE(V1)
{
pinValue = param.asInt();
}
BLYNK_READ(V5)
{
Blynk.virtualWrite(5,RH); // virtualpin 8 distance
}
BLYNK_READ(V6)
{
Blynk.virtualWrite(6,temp); // virtualpin 8 distance
}
void loop()
{
Blynk.run();
timer.run();
if (pinValue==0)
{
// some code here
}
else //(digitalRead(sensor_pin) == 1)
{
// some other code
}}
else {
// a lot of code here
pinValue=0; // here i set pinValue to 0 again in order to return to mode1
}
}
BLYNK_READ(V1)
{
Blynk.virtualWrite(1,pinValue); // virtualpin 1 state
}
//End of program