Yes you are right, I changed it now to pinMode
After this changed this, it worked but the timer wont start.
I know the setup is for things that only need to be done once, and the loop is for repeating things. Thats why I made the if/else statement in the loop part.
Am I wrong ?
Is there any change you could just look at the code and help me with the code. I now get send from pillar to post.
My questions are to summarize:
how come Blynk is responding to IF/ELSE but not to my timeout timer.
In reality, the code doesn’t need to be repeated at all.
It simply needs to run once when your BLYNK_WRITE(V1) callback is triggered, so that’s where the code should be located.
I’m not going to write your code for you. I took the time to write two topics which explain how to use virtual pins to control physical devices, and how to use timeout timers. If you’d taken the time to study them your project would have been working a long time ago.
Anyone reading this topic in future, and looking for a solution to this issue, PLEASE DO NOT USE THIS CODE!
One of the basic principals of Blynk is that the void loop should be kept free of unnecessary code - otherwise you will suffer unwanted/unnecessary disconnections from the Blynk server in the medium to long term.
The void loop should look like this:
void loop()
{
Blynk.run();
timer.run();
}
As already explained, The BLYNK_WRITE(V1) should look like this
BLYNK_WRITE(V1)
{
if (param.asInt() == 1)
{
digitalWrite(relay, HIGH);
timer.setTimeout(10000L, []()
{
// When the timer completes, any code here will be executed:
digitalWrite(relay, LOW);
});
}
else
{
digitalWrite(relay, LOW);
}
}