As a title, to avoid accidental pressures, i need to create a button mode push with a delay of 3 seconds before start the code, and break if the time is less of 3 seconds.
I try with this sketch but there is something wrong
long currentMillis = 0;
int periodo = 3000;
long startMillis = 0;
BLYNK_WRITE(V1) {
int state = param.asInt();
bool premuto = false;
if (state == 1) {
premuto = true;
startMillis = millis();
currentMillis = startMillis;
while (currentMillis < (startMillis + periodo)) {
currentMillis = millis();
if (param.asInt() == 0) premuto = false;
else premuto = true;
}
if (currentMillis >= startMillis && premuto)
digitalWrite(15, LOW);
}
else
digitalWrite(15, HIGH);
}
Here is my example of a safety switch using a slider… I will eventually get around to making one for a button that requires a long press… but probably not before Blynk 2.0 is released, thus nullifying the need anyhow as it will apparently have such a feature?
else you can do that too, press 2 sec to unlock any buttons!
/**************** LOCK UNLOCK **************/
BLYNK_WRITE(V50) { // button to be held down to activate
if (param.asInt() and !LongHold ) {
ButtonTimer = timer.setTimeout(2000, LongHoldDetect); // press 2 sec
ButtonPressed = true;
// Button has been released
} else {
ButtonPressed = false; // Reset press flag
// If the long hold function wasn't called, it's a short press.
if (!LongHold) {
timer.deleteTimer(ButtonTimer); // Kill the long hold timer if it hasn't been activated.
// Reset the long press flag
LongHold = false;
greenLed.off();
redLed.on();
}
}
}
// Checks for long press condition on SETTINGS button
void LongHoldDetect() {
// If the button is still depressed, it's a long hold
if (ButtonPressed) {
LongHold = true;
greenLed.on();
redLed.off();
}
}
BLYNK_WRITE(V51) { // Reset button
if (param.asInt()) {
if (LongHold = true) {
ButtonPressed = false;
LongHold = false;
greenLed.off();
redLed.on();
}
}
}