Skip to content

Commit a18d3f6

Browse files
committed
nonBlokingBlink
1 parent b5f7257 commit a18d3f6

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

arduino_bootstrapper/core/BootstrapManager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,21 @@ void BootstrapManager::bootstrapLoop(void (*manageDisconnections)(), void (*mana
3434

3535
mqttClient.loop();
3636

37+
}
38+
39+
// Blink LED_BUILTIN without bloking delay
40+
void BootstrapManager::nonBlokingBlink() {
41+
unsigned long currentMillis = millis();
42+
if (currentMillis - previousMillis >= interval && ledTriggered) {
43+
// save the last time you blinked the LED
44+
previousMillis = currentMillis;
45+
// blink led
46+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
47+
blinkCounter++;
48+
if (blinkCounter >= blinkTimes) {
49+
blinkCounter = 0;
50+
ledTriggered = false;
51+
digitalWrite(LED_BUILTIN, HIGH);
52+
}
53+
}
3754
}

arduino_bootstrapper/core/BootstrapManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class BootstrapManager {
2020
public:
2121
void bootstrapSetup(void (*manageDisconnectionFunction)(), void (*manageHardwareButton)(), void (*callback)(char*, byte*, unsigned int));
2222
void bootstrapLoop(void (*manageDisconnectionFunction)(), void (*manageQueueSubscription)(), void (*manageHardwareButton)());
23+
void nonBlokingBlink();
2324

2425
};
2526

arduino_bootstrapper/core/Helpers.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
String lastMQTTConnection = "OFF";
55
String lastWIFiConnection = "OFF";
6+
unsigned long previousMillis = 0;
7+
const long interval = 200;
8+
bool ledTriggered = false;
9+
int blinkCounter = 0;
10+
const int blinkTimes = 6;
611

712
void Helpers::smartPrint(String msg) {
813

arduino_bootstrapper/core/Helpers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
extern String lastMQTTConnection;
77
extern String lastWIFiConnection;
8+
// Blink LED vars
9+
extern unsigned long previousMillis; // will store last time LED was updated
10+
extern const long interval; // interval at which to blink (milliseconds)
11+
extern bool ledTriggered;
12+
extern int blinkCounter;
13+
extern const int blinkTimes; // 6 equals to 3 blink on and 3 off
814

915
const int DELAY_10 = 10;
1016
const int DELAY_50 = 50;

0 commit comments

Comments
 (0)