Boss lady
Boss lady
DIIDevHeads IoT Integration Server
Created by Camila_99$$ on 6/11/2024 in #middleware-and-os
Managing Relay Sequences with Non-Blocking Delays on Arduino Leonardo
Use millis() instead of delay this should fix it 👇
#include <OneButton.h>

const byte buttonPin = 13;
OneButton button(buttonPin, true);
enum { SECURITE, SEQUENCE } etatCourant = SECURITE;

unsigned long startMillis;
bool timing = false;
const unsigned long delayDuration = 480000; // 8 minutes

void doubleclick() {
switch (etatCourant) {
case SECURITE:
etatCourant = SEQUENCE;
start();
startMillis = millis();
timing = true;
break;
case SEQUENCE:
// Optionally handle double-click in SEQUENCE state
break;
}
}

void setup() {
pinMode(buttonPin, INPUT_PULLUP);
button.attachDoubleClick(doubleclick);
// Other setup code...
}

void loop() {
button.tick();

if (timing && (millis() - startMillis >= delayDuration)) {
etatCourant = SECURITE;
timing = false;
}

// Other loop code...
}

void start() {
// Start sequence actions
}
#include <OneButton.h>

const byte buttonPin = 13;
OneButton button(buttonPin, true);
enum { SECURITE, SEQUENCE } etatCourant = SECURITE;

unsigned long startMillis;
bool timing = false;
const unsigned long delayDuration = 480000; // 8 minutes

void doubleclick() {
switch (etatCourant) {
case SECURITE:
etatCourant = SEQUENCE;
start();
startMillis = millis();
timing = true;
break;
case SEQUENCE:
// Optionally handle double-click in SEQUENCE state
break;
}
}

void setup() {
pinMode(buttonPin, INPUT_PULLUP);
button.attachDoubleClick(doubleclick);
// Other setup code...
}

void loop() {
button.tick();

if (timing && (millis() - startMillis >= delayDuration)) {
etatCourant = SECURITE;
timing = false;
}

// Other loop code...
}

void start() {
// Start sequence actions
}
6 replies