Skip to content

Commit 4c824ad

Browse files
committed
improve blinker
1 parent 298d859 commit 4c824ad

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/Helpers/Blinker.cpp

+18-8
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,31 @@ Colour blue = {0, 0, 25};
1515
Colour green = {0, 25, 0};
1616
Colour red = {25, 0, 0};
1717
Colour orange = {25, 17, 0};
18-
#endif
18+
Colour black = {0, 0, 0};
19+
20+
Blinker::Blinker(int pin, rgb_led_color_order_t order)
21+
: _pin(pin)
22+
, _ledState(false)
23+
, _interval(100)
24+
, _lastInterval(0)
25+
, _order(order)
26+
, _colour(black) {
27+
// empty
28+
}
29+
30+
#else
1931

2032
Blinker::Blinker(int pin, uint8_t valOff)
2133
: _pin(pin)
22-
, _valOff(valOff)
2334
, _ledState(false)
2435
, _interval(100)
2536
, _lastInterval(0)
26-
#ifdef RGB_BUILTIN
27-
, _colour(blue)
28-
#endif
29-
{
37+
, _valOff(valOff) {
3038
// empty
3139
}
3240

41+
#endif
42+
3343
#ifdef RGB_BUILTIN
3444
void Blinker::on(Colour colour, uint32_t interval) {
3545
#else
@@ -42,7 +52,7 @@ void Blinker::on(uint32_t interval) {
4252
_lastInterval = millis() - _interval;
4353
_ledState = true;
4454
#ifdef RGB_BUILTIN
45-
rgbLedWrite(_pin, _colour.red, _colour.green, _colour.blue);
55+
rgbLedWriteOrdered(_pin, _order, _colour.red, _colour.green, _colour.blue);
4656
#else
4757
digitalWrite(_pin, ~_valOff);
4858
#endif
@@ -65,7 +75,7 @@ void Blinker::loop() {
6575
if (_ledState) {
6676
rgbLedWrite(_pin, 0, 0, 0);
6777
} else {
68-
rgbLedWrite(_pin, _colour.red, _colour.green, _colour.blue);
78+
rgbLedWriteOrdered(_pin, _order, _colour.red, _colour.green, _colour.blue);
6979
}
7080
#else
7181
if (_ledState) {

src/Helpers/Blinker.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,31 @@ extern Colour blue;
2626
extern Colour green;
2727
extern Colour red;
2828
extern Colour orange;
29+
extern Colour black;
2930
#endif
3031

3132
class Blinker {
3233
public:
33-
explicit Blinker(int pin, uint8_t valOff = LOW);
3434
#ifdef RGB_BUILTIN
35+
explicit Blinker(int pin, rgb_led_color_order_t order = LED_COLOR_ORDER_GRB);
3536
void on(Colour colour, uint32_t interval = 0);
3637
#else
38+
explicit Blinker(int pin, uint8_t valOff = LOW);
3739
void on(uint32_t interval = 0);
3840
#endif
3941
void off();
4042
void loop();
4143

4244
protected:
4345
const int _pin;
44-
const uint8_t _valOff;
4546
bool _ledState;
4647
uint32_t _interval;
4748
uint32_t _lastInterval;
4849
#ifdef RGB_BUILTIN
50+
rgb_led_color_order_t _order;
4951
Colour _colour;
52+
#else
53+
const uint8_t _valOff;
5054
#endif
5155
};
5256

0 commit comments

Comments
 (0)