It’s certainly a software issue. All the hardware does is go HIGH when it’s being touched, and LOW when it’s not.
I’m not convinced by @daveblynk’s idea, because a Blynk.virtualWrite should’t trigger a BLYNK_WRITE on the same virtual pin, but it’s certainly worth a try.
Personally, I’d stick lots more serial prints in there and try to work out what’s happening with each of the variables at each stage in the process. Trying to step through the code on my iPad isn’t working for my slightly frazzled brain at the moment
Check out my method of doing a similar thing with actual Sonoff… Note how I have a flag routine to prevent sequential action when holding the button down… or reacting to both button press and release.
When Coping the Examples from the Sketch Builder, try to make sure that you copy them correctly. While changing the condition for the digital read is a valid change (depending on how the button is wired), I am not sure why you would also change the conditions for the flag.
From Sketch Builder:
void checkPhysicalButton()
{
if (digitalRead(btnPin) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState != LOW) {
// Toggle LED state
ledState = !ledState;
digitalWrite(ledPin, ledState);
// Update Button Widget
Blynk.virtualWrite(V2, ledState);
}
btnState = LOW;
} else {
btnState = HIGH;
}
}
From Your Code:
void checkPhysicalButton()
{
if (digitalRead(TeclaLuzPrincipal) == HIGH) {
Serial.println("Apretado Boton");
if (EstadoTeclaPrincipal != LOW) {
// Toggle LED state
EstadoLuzPrincipal = !EstadoLuzPrincipal;
digitalWrite(LuzPrincipal, EstadoLuzPrincipal);
// Update Button Widget
Blynk.virtualWrite(V30, EstadoTeclaPrincipal);
}
EstadoTeclaPrincipal = HIGH; //Change this back to EstadoTeclaPrincipal = LOW;
} else {
EstadoTeclaPrincipal = LOW; //Change this back to EstadoTeclaPrincipal = HIGH;
}
}