Skip to content

Commit 2ec235c

Browse files
committed
Merge branch 'dev'
2 parents d0f737e + 33391b8 commit 2ec235c

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v2.2.0 (2021-12-17)
4+
5+
- Fixes a bug where no default speed is set
6+
- Fixes a bug in the SerialBlink example where `Serial.begin()` is not called
7+
- `BaseFader` now supports custom value ranges (default = 255)
8+
- Small code speedup in `BaseFader`
9+
310
## v2.1.0 (2021-12-16)
411

512
- Removed default speeds from methods

examples/SerialBlink/SerialBlink.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class SerialBlinker : public BaseBlinker
1010
public:
1111
void write(int state) override
1212
{
13-
Serial.print("LED: ");
1413
Serial.println(state);
1514
}
1615
};
@@ -19,6 +18,7 @@ SerialBlinker myBlinker;
1918

2019
void setup()
2120
{
21+
Serial.begin(9600);
2222
myBlinker.pattern(2, 4);
2323
}
2424

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Blinkenlight",
3-
"version": "2.1.0",
3+
"version": "2.2.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": {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Blinkenlight
2-
version=2.1.0
2+
version=2.2.0
33
author=Thomas Feldmann <mail@tfeldmann.de>
44
maintainer=Thomas Feldmann <mail@tfeldmann.de>
55
sentence=Supercharge your status LEDs / beepers

src/BaseBlinker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ BaseBlinker::BaseBlinker()
55
{
66
permanent(LOW);
77
write(LOW);
8+
setSpeed(SPEED_FAST);
89
}
910

1011
void BaseBlinker::setSpeed(uint16_t on_ms)

src/BaseFader.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,36 @@ static const uint8_t LED_LOG_CURVE[256] = {
2828
class BaseFader : public BaseBlinker
2929
{
3030
public:
31-
BaseFader(bool logarithmic = false, int fadeSpeed = 30)
31+
BaseFader(bool logarithmic = false, int fadeSpeed = 30, int range = 255)
3232
: BaseBlinker(),
3333
output_(0),
34-
fadeSpeed_(abs(fadeSpeed)),
34+
lastUpdate_(millis()),
3535
logarithmic_(logarithmic),
36-
lastUpdate_(millis())
36+
fadeSpeed_(abs(fadeSpeed)),
37+
range_(range)
3738
{
3839
}
3940

4041
int update()
4142
{
4243
int state = BaseBlinker::update();
43-
uint32_t time = millis();
44-
if (time - lastUpdate_ > 10)
44+
uint32_t ms = millis();
45+
46+
if (ms - lastUpdate_ > 10)
4547
{
46-
lastUpdate_ = time;
47-
int diff = state * 255 - output_;
48-
output_ += constrain(diff, -fadeSpeed_, fadeSpeed_);
48+
lastUpdate_ = ms;
49+
int diff = state * range_ - output_;
4950

50-
// only write changes
51+
// we only call `write` on changes
5152
if (diff)
5253
{
54+
output_ += constrain(diff, -fadeSpeed_, fadeSpeed_);
5355
int result = logarithmic_ ? LED_LOG_CURVE[output_] : output_;
5456
write(result);
5557
return result;
5658
}
5759
}
58-
if (logarithmic_)
59-
return LED_LOG_CURVE[output_];
60-
return output_;
60+
return logarithmic_ ? LED_LOG_CURVE[output_] : output_;
6161
}
6262

6363
virtual void write(int state)
@@ -75,7 +75,9 @@ class BaseFader : public BaseBlinker
7575

7676
private:
7777
int output_;
78-
uint8_t fadeSpeed_;
79-
bool logarithmic_;
8078
uint32_t lastUpdate_;
79+
80+
bool logarithmic_;
81+
int fadeSpeed_;
82+
int range_;
8183
};

0 commit comments

Comments
 (0)