Skip to content

Commit ab4d47b

Browse files
committed
Merge commit '2b749fc5b576abfe0a24f1d4f0253942c4d75128'
2 parents 41bfcee + 2b749fc commit ab4d47b

23 files changed

+604
-396
lines changed

.github/workflows/tests.yml

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
"examples/Pattern",
3030
"examples/Pattern2",
3131
"examples/FadingBlink",
32+
"examples/CustomSpeed",
33+
"examples/SpeedAdjustment",
3234
]
3335

3436
# Steps represent a sequence of tasks that will be executed as part of the job

CHANGELOG.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Changelog
2+
3+
## v2.0.0 (2021-12-16)
4+
5+
- **Revamped API!**
6+
- New: writes the state only on changes, not on every update
7+
- Renamed the classes and header files:
8+
- `IndicatorPin` -> `Indicator`
9+
- `FadingIndicatorPin` -> `FadeIndicator`
10+
- `Indicator` -> `BaseIndicator`
11+
- `FadingIndicator` -> `BaseFadeIndicator`
12+
- Code cleanups
13+
- Uses GitHub Actions for tests
14+
15+
## v1.2.0 (2021-11-15)
16+
17+
- Renamed `configure`-method
18+
19+
## v1.1.0 (2021-11-12)
20+
21+
- renamed `count()` method to `pattern()`
22+
23+
## v1.0.1 (2021-11-12)
24+
25+
- Initial release

README.md

+70-42
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,28 @@
1212
- Basics: On / off / toggle
1313
- Supports blink patterns in the style of "Blink x times, pause, blink y times, repeat"
1414
- Supports infinite blinking
15-
- Supports single flashes
15+
- Supports single flashes and pauses, resuming the previous mode
16+
- Completely non-blocking (no `delay()`)
1617
- 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
1819
- 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)
2222

2323
## Example
2424

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:
2726

28-
`Blink 2x → Short pause → Blink 3x → Long pause → Repeat`
27+
- Blink 2x
28+
- Short pause
29+
- Blink 3x
30+
- Long pause
31+
- Repeat
2932

3033
```C
31-
#include <FadingIndicatorPin.h>
34+
#include <FadeIndicator.h>
3235

33-
FadingIndicatorPin led(13);
36+
FadeIndicator led(13);
3437

3538
void setup()
3639
{
@@ -43,16 +46,22 @@ void loop()
4346
}
4447
```
4548
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+
4655
## Full API
4756
4857
```C
4958
// Without fading effect:
50-
#include <IndicatorPin.h>
51-
IndicatorPin myPin(13);
59+
#include <Indicator.h>
60+
Indicator myPin(13);
5261
5362
// With fading effect:
54-
#include <FadingIndicatorPin.h>
55-
FadingIndicatorPin myPin(13);
63+
#include <FadeIndicator.h>
64+
FadeIndicator myPin(13);
5665
5766
// now in your code you can do:
5867
myPin.permanent(LOW);
@@ -61,45 +70,63 @@ myPin.blink();
6170
```
6271

6372
```C
73+
// set permanently ON
74+
void on();
75+
76+
// set permanently OFF
77+
void off();
78+
6479
// toggle between on / off
6580
void toggle();
6681

6782
// set ON / OFF permanently
6883
void permanent(bool enable);
6984

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);
7287

7388
// blink `num` times, then long pause
7489
// 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);
7691

7792
// blink `num1` times, short pause, blink `num2` times, long pause
7893
// 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);
8095

8196
// turn ON for the given duration in ms. Continues in the previous mode afterwards.
8297
void flash(uint16_t duration_ms);
8398

99+
// turn OFF for the given duration in ms. Continues in the previous mode afterwards.
100+
void pause(uint16_t duration_ms);
101+
84102
// 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
103130
bool isOn();
104131

105132
// You must call this in your loop!
@@ -112,10 +139,11 @@ int update();
112139
113140
No problem! You have two options.
114141
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`.
119147
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!

example_build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pio ci examples/$1 --board=micro --lib=src
File renamed without changes.

examples/Blink/Blink.ino

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
Start a blinking pattern on the built-in LED with a smooth fading effect.
33
*/
44

5-
#include <FadingIndicatorPin.h>
5+
#include <FadeIndicator.h>
66

7-
// Use `FadingIndicatorPin` for a smooth fade.
8-
// If you want hard blinking, use `IndicatorPin`.
9-
FadingIndicatorPin led(13);
7+
// We use `FadeIndicator` for a smooth fade.
8+
FadeIndicator led(13);
109

1110
void setup()
1211
{

examples/CustomSpeed/CustomSpeed.ino

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <Indicator.h>
2+
3+
Indicator led(13);
4+
SpeedSetting mySettings = {
5+
.on_ms = 100,
6+
.off_ms = 100,
7+
.pause_ms = 2000,
8+
.ending_ms = 2000,
9+
};
10+
11+
void setup()
12+
{
13+
// blink 2x on repeat with custom settings
14+
led.pattern(2, true, mySettings);
15+
}
16+
17+
void loop()
18+
{
19+
led.update();
20+
}

examples/FadingBlink/FadingBlink.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
Start a blinking pattern on the built-in LED with a smooth fading effect.
33
*/
4-
#include <FadingIndicatorPin.h>
4+
#include <FadeIndicator.h>
55

6-
FadingIndicatorPin led(13);
6+
FadeIndicator led(13);
77

88
void setup()
99
{

examples/GenericBlink/GenericBlink.ino

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
This example shows how to use a generic indicator.
33
The `update()` method returns HIGH or LOW that you can use however you want.
44
5-
Of course this example would be easer with a `IndicatorPin` which handles the
5+
Of course this example would be easer with a `Indicator` which handles the
66
digital output automatically.
77
*/
8-
#include <Indicator.h>
8+
#include <BaseIndicator.h>
99

10-
Indicator myIndicator;
10+
BaseIndicator myIndicator;
1111

1212
void setup()
1313
{
@@ -17,5 +17,6 @@ void setup()
1717

1818
void loop()
1919
{
20-
digitalWrite(13, myIndicator.update());
20+
bool isOn = myIndicator.update();
21+
digitalWrite(13, isOn);
2122
}

examples/Pattern/Pattern.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <IndicatorPin.h>
1+
#include <Indicator.h>
22

3-
IndicatorPin led(13);
3+
Indicator led(13);
44

55
void setup()
66
{

examples/Pattern2/Pattern2.ino

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
#include <IndicatorPin.h>
1+
#include <Indicator.h>
22

3-
IndicatorPin led(13);
3+
Indicator led(13);
44

55
void setup()
66
{
77
// This will set the LED to pattern mode:
88
//
9-
// 1. blink three times
9+
// 1. blink two times
1010
// 2. pause
11-
// 3. blink five times
11+
// 3. blink three times
1212
// 4. longer pause
1313
//
1414
// (repeat)
15-
led.pattern(3, 5);
15+
led.pattern(2, 3);
1616
}
1717

1818
void loop()

examples/SerialBlink/SerialBlink.ino

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* This example does not blink a light, but outputs its state directly to the Serial
3+
* port.
4+
*/
5+
6+
#include <BaseIndicator.h>
7+
8+
class SerialBlinker : public BaseIndicator
9+
{
10+
public:
11+
void write(int state) override
12+
{
13+
Serial.print("LED: ");
14+
Serial.println(state);
15+
}
16+
};
17+
18+
SerialBlinker myBlinker;
19+
20+
void setup()
21+
{
22+
myBlinker.pattern(2, 4);
23+
}
24+
25+
void loop()
26+
{
27+
myBlinker.update();
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <FadeIndicator.h>
2+
3+
FadeIndicator led(13);
4+
5+
uint32_t lastSwitch;
6+
bool isFast;
7+
8+
void setup()
9+
{
10+
isFast = false;
11+
lastSwitch = millis();
12+
13+
led.blink(SPEED_SLOW);
14+
}
15+
16+
void loop()
17+
{
18+
led.update();
19+
20+
// toggle speed every 3 seconds
21+
if (millis() - lastSwitch > 3000)
22+
{
23+
lastSwitch = millis();
24+
isFast = !isFast;
25+
led.blink(isFast ? SPEED_FAST : SPEED_SLOW);
26+
}
27+
}

library.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Indicator",
3-
"version": "1.2.0",
3+
"version": "2.0.0",
44
"description": "This library gives you non-blocking blinking patterns and smooth fade effects for your LEDs, buzzers or any other status indicators",
55
"keywords": "led, signal, fading, blink",
66
"repository": {
@@ -22,7 +22,10 @@
2222
"platforms": "*",
2323
"export": {
2424
"exclude": [
25-
"*.sh"
25+
"*.sh",
26+
".github",
27+
"platformio.ini",
28+
"test"
2629
]
2730
}
2831
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Indicator
2-
version=1.2.0
2+
version=2.0.0
33
author=Thomas Feldmann <mail@tfeldmann.de>
44
maintainer=Thomas Feldmann <mail@tfeldmann.de>
55
sentence=Supercharge your status LEDs / beepers

0 commit comments

Comments
 (0)