I’m trying to get a simple button to run a function.
Hardware: Particle Photon
I have other values flowing from like temp and humidity and that is showing up just fine in Blynk. I have no delays in the loop and actual did a loop count to verify that it is looping around 1000 a second.
The button is configured as “push” on V2.
Can anybody see what I’m doing wrong or is there a better way to handle this?
note: I cut out a lot of the other code that checks on the status of other pins and calls to particle’s web hooks but this should be the core of the logic to run a function.
int toggle_from_blynk = 0;
void setup(){
Blynk.begin(auth);
}
void loop(){
Blynk.run();
/*
A lot of other stuff runs here
*/
if(toggle_from_blynk){
toggle_from_blynk = 0;
/* This will be the call to the function */
toggleRelay("1");
}
}
int toggleRelay(String command){
digitalWrite(relayPin,HIGH);
delay(2000);
digitalWrite(relayPin,LOW);
Particle.publish("Toggled", 60, PRIVATE);
return 1;
}
BLYNK_WRITE(V2){
toggle_from_blynk = 1;
}