BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Need Help with a counter based off a Button connected to a relay

Yes.
BLYNK_WRITE(vPin) is a special callback function which triggers automatically when the value of the virtual pin changes because of input via the app or an HTTP(S) update.
You can’t put this function inside another function.

Maybe if you explained properly what it is you are trying to achieve, and added some in-code documentation to your sketch, we’d be able to understand your issue and advise on the best way to solve it.

Pete.

And that is exactly what I am trying to do. I am trying to reset a counter. This counter is based off a relay on a digital pin. When the relay is triggered via the app, it starts counting. As I explained in my first post, I have a pump that will always be putting out 4 gallons per minute. I have made counters for hour meters for the pump, an air compressor, as well as a season long hour meter.

I also have counters to count the amount of water used each time watering, as well as the amount of hours that the pump has been on. These counters are all blynk timers with different intervals.

My question is in regards to resetting the counters. My code references virtual pin 30 and 31. On the app, I have two buttons that are tied to V30 and V31. I want to be able to reset these two counters by pushing the button and holding for 1 second, so that I dont accidentally hit the button and reset it.

to the best of my understanding, this code should run the function every 1 second, and if it see the button is pushed (variable tied to virtual pin = 1,) then it will set the variable attached to the counter to go to 0 using an if function. If the button is not pushed, it says to write the variable that’s stored.

I have tried not putting this code inside my reset function but its not reading the button as high or low but rather just reading the number of the virtual pin. I set it up to just print to serial monitor what it was receiving from BLYNK_WRITE.

This is my updated code for just the reset. I removed the blynk timer. Is there a way that i could require a 2 second press of the button to reset?


BLYNK_WRITE(V30);

g = param.asInt(); /

if ( g == 1)
{
  Blynk.virtualWrite(V17, 0);

}
else {
  Blynk.virtualWrite(V17, m);
}


BLYNK_WRITE(V31);

h = param.asInt(); /

if ( h == HIGH)
{
  Blynk.virtualWrite(V17, 0);

}
else {
  Blynk.virtualWrite(V17, m);
}

Which code are you referring to?
If it’s the code in post #21 then, as I explained before, it doesn’t work because you can’t put a BLYNK_WRUTE(vPin) callback function inside another function.

Maybe you should take a look at topics like this one:

or this one:

Pete.

Deleted!

Pete.