I believe the correct way of doing this would be…
#define outputPin 1
#define inputPin V1
No delays, garsh darnit or we kick your donkey outta here (but we keep the Porch
).
Actually very short delays CAN be used, as long as they are not cumulative or large enough in of themselves to cause a heartbeat timeout (generally even 1-2 seconds can start causing potential issues)… @Jamin’s solution, while so condensed into uber coder shorthand as to be indistinguishable from magic … would have better suited your needs, and allowed for a non-blocking relay latch ranging well into multiples of minutes/hours if needed.
Goober level coder translation follows
BLYNK_WRITE(inputPin) {
if (param.asInt()) { // act only on the HIGH and not the LOW of the momentary
digitalWrite(outputPin, !digitalRead(outputPin)); // invert pin state just once
tripWire.setTimeout(1000L, [](){
digitalWrite(outputPin, !digitalRead(outputPin)); // then invert it back after 1000ms
});
}
}
That == this…
#define outputPin 1
#define inputPin V1
BLYNK_WRITE(inputPin) {
if (param.asInt() == 1) { // Run only when ON/HIGH state of button
digitalWrite(outputPin, HIGH); // activate relay
tripWire.setTimeout(1000L, DeactivateRelay); // In 1 second, run the deactivate function call
}
}
void DeactivateRelay() {
digitalWrite(outputPin, LOW); // Deactivate relay
}
And, yes, I know it is pronounced Porsche… silly little cars… Lamborghini all the way!