Skip to content

Commit

Permalink
add optional speed parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeldmann committed Dec 20, 2021
1 parent 302b80a commit f666ee0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## In progress

- `logarithmic` is now `true` by default
- Add `pattern` and `flash` method with `SpeedSetting` parameter
- Added example `FadeComparison`

## v2.2.0 (2021-12-17)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ void blink();
// repeats, if `repeat` is set, OFF otherwise.
void pattern(int num, bool repeat = true);

// same as before, but accepts a speed setting
void pattern(int num, SpeedSetting speed, bool repeat = true);

// blink `num1` times, short pause, blink `num2` times, long pause
// repeats, if `repeat` is set, OFF otherwise.
void pattern(int num1, int num2, bool repeat = true);

// same as before, but accepts a speed setting
void pattern(int num1, int num2, SpeedSetting speed, bool repeat = true);

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

Expand Down
2 changes: 1 addition & 1 deletion examples/Pattern2/Pattern2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void setup()
// 4. longer pause
//
// (repeat)
led.pattern(2, 3);
led.pattern(2, 3, SPEED_RAPID);
}

void loop()
Expand Down
6 changes: 2 additions & 4 deletions examples/SpeedAdjustment/SpeedAdjustment.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ void setup()
{
isFast = false;
lastSwitch = millis();

led.setSpeed(SPEED_SLOW);
led.blink();
led.blink(SPEED_SLOW);
}

void loop()
Expand All @@ -23,6 +21,6 @@ void loop()
{
lastSwitch = millis();
isFast = !isFast;
led.setSpeed(isFast ? SPEED_FAST : SPEED_SLOW);
led.blink(isFast ? SPEED_FAST : SPEED_SLOW);
}
}
18 changes: 18 additions & 0 deletions src/BaseBlinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,23 @@ void BaseBlinker::blink()
update();
}

void BaseBlinker::blink(SpeedSetting speed)
{
setSpeed(speed);
blink();
}

void BaseBlinker::pattern(int num, bool repeat)
{
pattern(num, 0, repeat);
}

void BaseBlinker::pattern(int num, SpeedSetting speed, bool repeat)
{
setSpeed(speed);
pattern(num, 0, repeat);
}

void BaseBlinker::pattern(int num1, int num2, bool repeat)
{
repeat_ = repeat;
Expand All @@ -94,6 +106,12 @@ void BaseBlinker::pattern(int num1, int num2, bool repeat)
update();
}

void BaseBlinker::pattern(int num1, int num2, SpeedSetting speed, bool repeat)
{
setSpeed(speed);
pattern(num1, num2, repeat);
}

void BaseBlinker::flash(uint16_t duration_ms)
{
flashStart_ = millis();
Expand Down
9 changes: 9 additions & 0 deletions src/BaseBlinker.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,23 @@ class BaseBlinker
// blink infinitely
void blink();

// blink infinitely with new speed setting
void blink(SpeedSetting speed);

// blink `num` times, then long pause
// repeats if `repeat` is set, otherwise it is OFF afterwards
void pattern(int num, bool repeat = true);

// same as before, but accepts a speed setting
void pattern(int num, SpeedSetting speed, bool repeat = true);

// blink `num1` times, short pause, blink `num2` times, long pause
// repeats if `repeat` is set, otherwise it is OFF afterwards
void pattern(int num1, int num2, bool repeat = true);

// same as before, but accepts a speed setting
void pattern(int num1, int num2, SpeedSetting speed, bool repeat = true);

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

Expand Down

0 comments on commit f666ee0

Please sign in to comment.