So basically, i am working on a Feedback system for Home automation ,which updates the state of the physical button connected to your board onto the Blynk app, so that you can control your lights from both - manually and through the app.I am using an ESP32 board.The state of the physical button connected to the board is taken and is sent to the virtual button on the blynk app,using the native logic of blynk i.e param.asInt().hence i cannot use the logic of the normal switch like:
if (digitalRead(PUSH_BUTTON_1) == LOW) {
digitalWrite(RELAY_PIN_1, HIGH);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_1, HIGH);}
as i have to use relay1State which is given as param.asInt(); to update the blynk app.Also if i use this type of code i am incurring sequential toggles in the blynk app:
void checkPhysicalButton()
{
if (digitalRead(PUSH_BUTTON_1) == HIGH) {
relay1State =!relay1State;
digitalWrite(RELAY_PIN_1, relay1State);
Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
}
else {
digitalWrite(RELAY_PIN_1, relay1State);
Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
}}
so hence i have to use my the pushbutton state logic to remove the sequential toggles .But i am unable to use it as a "Press for on, release for off" switch. it works as a Toggle switch- "press once to turn and press again to turn it off." i want to change this logic to Press for on, release for off.Please help me.Thank you!
BLYNK_WRITE(VPIN_BUTTON_1) {
relay1State = param.asInt();
digitalWrite(RELAY_PIN_1, relay1State);
}
void checkPhysicalButton()
{
if (digitalRead(PUSH_BUTTON_1) == LOW) {
// pushButton1State is used to avoid sequential toggles
if (pushButton1State != LOW) {
// Toggle Relay state
relay1State = !relay1State;
digitalWrite(RELAY_PIN_1, relay1State);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
}
pushButton1State = LOW;
} else {
pushButton1State = HIGH;
}