-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathled.cpp
More file actions
69 lines (59 loc) · 1.46 KB
/
Copy pathled.cpp
File metadata and controls
69 lines (59 loc) · 1.46 KB
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
67
68
#include <Arduino.h>
#include "led.h"
#include "board_config.h"
Led led;
void Led::init(void)
{
if (done_init) {
return;
}
done_init = true;
#ifdef PIN_STATUS_LED
pinMode(PIN_STATUS_LED, OUTPUT);
#endif
#ifdef WS2812_LED_PIN
pinMode(WS2812_LED_PIN, OUTPUT);
ledStrip.begin();
#endif
}
void Led::update(void)
{
init();
const uint32_t now_ms = millis();
#ifdef PIN_STATUS_LED
switch (state) {
case LedState::ARM_OK: {
digitalWrite(PIN_STATUS_LED, STATUS_LED_OK);
last_led_trig_ms = now_ms;
break;
}
default:
if (now_ms - last_led_trig_ms > 100) {
digitalWrite(PIN_STATUS_LED, !digitalRead(PIN_STATUS_LED));
last_led_trig_ms = now_ms;
}
break;
}
#endif
#ifdef WS2812_LED_PIN
ledStrip.clear();
switch (state) {
case LedState::ARM_OK:
ledStrip.setPixelColor(0, ledStrip.Color(0, 255, 0));
#if WS2812_LED_NUM > 1
ledStrip.setPixelColor(1, ledStrip.Color(0, 255, 0)); //for db210pro, set the second LED to have the same output (for now)
#endif
break;
default:
ledStrip.setPixelColor(0, ledStrip.Color(255, 0, 0));
#if WS2812_LED_NUM > 1
ledStrip.setPixelColor(1, ledStrip.Color(255, 0, 0)); //for db210pro, set the second LED to have the same output (for now)
#endif
break;
}
if (now_ms - last_led_strip_ms >= 200) {
last_led_strip_ms = now_ms;
ledStrip.show();
}
#endif
}