-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_handler.cpp
66 lines (53 loc) · 1.49 KB
/
status_handler.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <Arduino.h>
#include "config.h"
#include "status_handler.h"
void blink(unsigned on_time){
// pinMode(LED_BUILTIN, OUTPUT); needs to be called before using this function
#ifdef USE_LED
//i don't think this if is needed lol
/*if(digitalRead(LED_BUILTIN) == HIGH) { //if the led is on, stop it
digitalWrite(LED_BUILTIN, LOW);
}
*/
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(on_time); // wait for time_out milliseconds
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
#endif
}
void rgb_color(unsigned red, unsigned green, unsigned blue) {
#ifdef USE_LED
#ifdef USE_RGB
analogWrite(RGB_PIN_RED, red);
analogWrite(RGB_PIN_GREEN, green);
analogWrite(RGB_PIN_BLUE, blue);
#endif
#endif
}
void rgb_blink(unsigned red, unsigned green, unsigned blue, unsigned on_time) {
#ifdef USE_LED
#ifdef USE_RGB
rgb_color(red, green, blue);
delay(on_time);
rgb_color(0,0,0);
#endif
#endif
}
[[noreturn]] void abort_blink(unsigned n_blinks, unsigned long_time, unsigned short_time){
while(42){
blink();
rgb_blink(255,0,0);
for(unsigned n = 1; n < n_blinks; ++n){
delay(short_time);
blink();
rgb_blink(255, 0, 0);
}
delay(long_time);
}
}
float batteryStatus() {
// read the input on analog pin 0:
int sensorValue = analogRead(ADC_BATTERY);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 4.3V):
float voltage = sensorValue * (4.3 / 1023.0);
return voltage;
}