Thnx for the examples, I can make this work perfectly with a physical button (I press the button, LED turns on for 5 seconds then goes off) - but not with a button widget.
Sketch start as planned, button widget is OFF, LED is OFF, nothing is printed on Serial Monitor (SM). I press the widget button, LED lights ON and SM prints as expected . . .after 5 seconds LED stays ON (should go OFF); and SM shows the sketch switching in and out of TurnOnWater() and TurnOffWater() in sequence.
#define BLYNK_PRINT Serial
char auth = "nnn";
char ssid = "nnn";
char pass = "nnn";
BlynkTimer timer; // define Blynk timere to determine when to check sensors
const int ledPin = 2;
int pinValue = 0;
long interval = 5000; // stop watering after interval
digitalWrite(ledPin, param.asInt()); // Sets ledPin HIGH or LOW depending on state of Button Widget.
pinValue = 0;
timer.setTimeout(interval, TurnOffWater); // Run TurnOffLWater() after set time.
pinValue = 0;
Blynk.virtualWrite(V5, 0); // set buttom LOW
Blynk.begin(auth, ssid, pass);
Blynk.virtualWrite(V5, 0); // set button LOW on startup
pinMode(2, OUTPUT); // test led
pinValue = digitalRead(ledPin);
if (pinValue == 1) // if button pressed
*Note the delays are just there to slow down the SM output.
I want to use the Button Widget as a SWITCH (not button), so that when I press it the LED turns ON, the widget stays on showing me that it is active, then after a set time it goes OFF.
What is wrong with my code please? As I said this works perfectly with a physical buttn, but not with the Blynk Button Widget in switch mode.