12
12
- Basics: On / off / toggle
13
13
- Supports blink patterns in the style of "Blink x times, pause, blink y times, repeat"
14
14
- Supports infinite blinking
15
- - Supports single flashes
15
+ - Supports single flashes and pauses, resuming the previous mode
16
+ - Completely non-blocking (no ` delay() ` )
16
17
- Parameters for pause- / off- / on-time duration can be adjusted on the fly
17
- - Super-nice fading effects (optional) with logarithmic brightness compensation
18
+ - Super-nice fading effects (optional) with logarithmic brightness compensation for LEDs
18
19
- Lightweight
19
- - Good-looking defaults (at least I tried)
20
- - Easily extendable
21
- - Non-blocking (no ` delay() ` ), no dynamic allocations
20
+ - Easily extendable to control components via SPI / CAN / I2C / UART ...
21
+ - Comes with good-looking defaults (at least I tried)
22
22
23
23
## Example
24
24
25
- This example blinks the built-in LED on pin 13 with a smooth fade effect and logarithmic
26
- brightness compensation in the following pattern:
25
+ This example blinks the built-in LED on pin 13 in the following pattern:
27
26
28
- ` Blink 2x → Short pause → Blink 3x → Long pause → Repeat `
27
+ - Blink 2x
28
+ - Short pause
29
+ - Blink 3x
30
+ - Long pause
31
+ - Repeat
29
32
30
33
``` C
31
- #include < FadingIndicatorPin .h>
34
+ #include < FadeIndicator .h>
32
35
33
- FadingIndicatorPin led (13);
36
+ FadeIndicator led (13);
34
37
35
38
void setup()
36
39
{
@@ -43,16 +46,22 @@ void loop()
43
46
}
44
47
```
45
48
49
+ Easy, uh? It's not only blinking, it does so with smooth fading effects and
50
+ logarithmic LED brightness compensation. Your boards never looked more professional! /s
51
+
52
+ > Note: If you don't love the fading effects, just use the `Indicator`-class instead of
53
+ > `FadeIndicator`.
54
+
46
55
## Full API
47
56
48
57
```C
49
58
// Without fading effect:
50
- #include <IndicatorPin .h>
51
- IndicatorPin myPin(13);
59
+ #include <Indicator .h>
60
+ Indicator myPin(13);
52
61
53
62
// With fading effect:
54
- #include <FadingIndicatorPin .h>
55
- FadingIndicatorPin myPin(13);
63
+ #include <FadeIndicator .h>
64
+ FadeIndicator myPin(13);
56
65
57
66
// now in your code you can do:
58
67
myPin.permanent(LOW);
@@ -61,45 +70,63 @@ myPin.blink();
61
70
```
62
71
63
72
``` C
73
+ // set permanently ON
74
+ void on ();
75
+
76
+ // set permanently OFF
77
+ void off ();
78
+
64
79
// toggle between on / off
65
80
void toggle ();
66
81
67
82
// set ON / OFF permanently
68
83
void permanent (bool enable);
69
84
70
- // blink infinitely. ` speed ` can be 0 (slow) or 1 (fast) .
71
- void blink(Speed speed = Speed::FAST );
85
+ // blink infinitely. Speed is fast by default .
86
+ void blink(SpeedSetting speed = SPEED_FAST );
72
87
73
88
// blink ` num ` times, then long pause
74
89
// repeats, if ` repeat ` is set, OFF otherwise.
75
- void pattern(int num, bool repeat = true, Speed speed = Speed::FAST );
90
+ void pattern(int num, bool repeat = true, SpeedSetting speed = SPEED_FAST );
76
91
77
92
// blink ` num1 ` times, short pause, blink ` num2 ` times, long pause
78
93
// repeats, if ` repeat ` is set, OFF otherwise.
79
- void pattern(int num1, int num2, bool repeat = true, Speed speed = Speed::FAST );
94
+ void pattern(int num1, int num2, bool repeat = true, SpeedSetting speed = SPEED_FAST );
80
95
81
96
// turn ON for the given duration in ms. Continues in the previous mode afterwards.
82
97
void flash(uint16_t duration_ms);
83
98
99
+ // turn OFF for the given duration in ms. Continues in the previous mode afterwards.
100
+ void pause(uint16_t duration_ms);
101
+
84
102
// setup the timing parameters
85
- void setTiming(
86
- uint16_t fast_on_ms,
87
- uint16_t fast_off_ms,
88
- uint16_t fast_pause_ms,
89
- uint16_t fast_ending_ms,
90
- uint16_t slow_on_ms,
91
- uint16_t slow_off_ms,
92
- uint16_t slow_pause_ms,
93
- uint16_t slow_ending_ms);
94
-
95
- // Hint: You can also modify the values directly, e.g.:
96
- myLed.fast_on_ms = 250;
97
-
98
- // shorthand for setting up the timing parameters by defining the fast ON duration in ms.
99
- // all other durations are derived from that with some internal factors.
100
- void setTiming(uint16_t on_ms);
101
-
102
- // ` true ` if the indicator is currently blinking, showing a pattern or flashing
103
+ void setSpeed(SpeedSetting setting);
104
+ // Available by default: SPEED_RAPID, SPEED_FAST, SPEED_SLOW
105
+
106
+ // Or use your own settings. SpeedSetting is a struct:
107
+ typedef struct
108
+ {
109
+ uint16_t on_ms;
110
+ uint16_t off_ms;
111
+ uint16_t pause_ms;
112
+ uint16_t ending_ms;
113
+ } SpeedSetting;
114
+
115
+ // ... alternatively you can setup the speed settings directly
116
+ void setSpeed(
117
+ uint16_t on_ms,
118
+ uint16_t off_ms,
119
+ uint16_t pause_ms,
120
+ uint16_t ending_ms);
121
+
122
+ // ... or by providing a single value, the other values are inferred from that
123
+ void setSpeed(uint16_t on_ms);
124
+
125
+ // Hint: You can also modify the values directly - even on the fly - e.g.:
126
+ myLed.settings.on_ms = 250;
127
+ myLed.settings.pause_ms = 2000;
128
+
129
+ // ` true ` if the indicator is currently blinking, showing a pattern, flashing or pausing
103
130
bool isOn();
104
131
105
132
// You must call this in your loop!
@@ -112,10 +139,11 @@ int update();
112
139
113
140
No problem! You have two options.
114
141
115
- - Use the generic `Indicator` class from `<Indicator.h>`. The `.update()`-method returns
116
- a boolean whether the status is currently `HIGH` or `LOW`. You can then send this
117
- value to your status indicator (see `examples/GenericBlink`). Use the `FadingIndictor`
118
- class if you want fading effects. Here the `update` method returns an integer `0..255`.
142
+ - Use the generic `BaseIndicator` class from `<BaseIndicator.h>`. The `.update()`-method
143
+ returns a boolean whether the status is currently `HIGH` or `LOW`. You can then send
144
+ this value to your status indicator (see `examples/GenericBlink`).
145
+ Use the `BaseFadeIndictor` class if you want fading effects. Here the `update` method
146
+ returns an integer `0..255`.
119
147
120
- - Subclass the `Indicator ` class with custom logic. This is what `IndicatorPin ` does
121
- internally (see `src/IndicatorPin .h`).
148
+ - Subclass the `BaseIndicator ` class with custom logic. This is what `Indicator ` does
149
+ internally (see `src/Indicator .h`). Have a look at the `SerialBlink` example!
0 commit comments