-
Notifications
You must be signed in to change notification settings - Fork 0
/
busy_wait.h
49 lines (39 loc) · 966 Bytes
/
busy_wait.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef BUSY_WAIT_H
#define BUSY_WAIT_H
#include <Arduino.h>
/*
busyWait(5000) will wait for 5 seconds
*/
void busyWait(unsigned long ms) {
unsigned long start = millis();
while ((millis() - start) < ms) {
/* sleep for 10 ms */
delay(10);
}
}
/*
busyWait(5000, &buttonState, HIGH); will wait for 5 seconds or until buttonState == HIGH
*/
void busyWaitOrCondition(unsigned long ms, volatile int* val, int expected) {
unsigned long start = millis();
while ((millis() - start) < ms && *val != expected) {
delay(10);
}
}
void busyWaitOrCondition(unsigned long ms, volatile uint8_t* val, uint8_t expected) {
unsigned long start = millis();
while ((millis() - start) < ms && *val != expected) {
delay(10);
}
}
void waitForCondition(volatile int* val, int expected) {
while (*val != expected) {
delay(10);
}
}
void waitForCondition(volatile uint8_t* val, uint8_t expected) {
while (*val != expected) {
delay(10);
}
}
#endif