I have added a Wemos D1 mini to the remote of my window blinds to make it an IOT device. It works with hard coded code and new I want to do the same via Blynk.
The problem is that when I push the button (D1), then the D1 output has to stay high for 2 seconds for it to work.
I have added this code, but without any success
BLYNK_WRITE(V5)
{
int pinData = param.asInt();
if (pinData == D1)
{
digitalWrite(D1, HIGH);
delay(2000);
digitalWrite(D1, LOW);
}
}
@Den_Olli please edit your post using the pencil icon at the bottom and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Beats me I’m just a noob. Maybe that’s not the correct name… I use it now and then and it works… maybe @PeteKnight can explain it from a C++ stand point but in layman’s terms I think it just uses the Millis() timer and does the calculations for you.
It is actually just a more compact way of writing code… at least that is all I use it for, particularly with my timer codes. I am sure there must be many more reasons for its use/benefits with actual real programers (AKA not me )
Basically this…
void setup() {
// setup stuff
// more setup stuff
// Timed Lambda Function - UpTime counter
timer.setInterval(1000L, []() { // Run every second
Blynk.virtualWrite(V0, millis() / 60000); // Display the UpTime in Minutes
}); // END Timer Function
}
…is just a ‘compact’ way of doing this…
void setup() {
// setup stuff
// more setup stuff
// Timed Lambda Function - UpTime counter
timer.setInterval(1000L, UpTime); // Run the function UpTime very second
}
void UpTime() {
Blynk.virtualWrite(V0, millis() / 60000); // Display the UpTime in Minutes
}
This is one of the solutions I had already found, but it doesn’t work in my case
when I push the button for a half second, then the led is also only on for a half second.
D1 is GPIO pin 5, so I guess that V5 is correct?
There is no connection or correlation between physical digital pins and virtual pins - they are totally separate entities.
In your code, the BLYNK_WRITE(V5) callback function is triggered automatically whenever the value of a widget connected to V5 changes.
If your button widget is connected to D5 rather than V5 then this function will never be executed.
@Den_Olli Ok This is happening because in button mode your button sends a 1 when you push and zero when you release. Change your button setting to switch in the app then in the timer function write a 0 to change the button back to off.