Skip to content

Commit

Permalink
add fade from-to example
Browse files Browse the repository at this point in the history
  • Loading branch information
jandelgado committed Nov 13, 2022
1 parent 3e4a9d1 commit 45f3dbe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ Example sketches are provided in the [examples](examples/) directory.
* [Candle effect](examples/candle)
* [Fade LED on](examples/fade_on)
* [Fade LED off](examples/fade_off)
* [Fade from-to effect](examples/fade_from_to)
* [Pulse effect](examples/pulse)
* [Controlling multiple LEDs in parallel](examples/multiled)
* [Controlling multiple LEDs in parallel (mbed)](examples/multiled_mbed)
* [Controlling multiple LEDs sequentially](examples/sequence)
Expand Down
23 changes: 23 additions & 0 deletions examples/fade_from_to/fade_from_to.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// JLed fade from-to example. Example randomly fades to a new level with
// and duration, choosing random values.
// Copyright 2022 by Jan Delgado. All rights reserved.
// https://github.com/jandelgado/jled
#include <jled.h>

auto led = JLed(5).On(1); // start with LED turned on

void setup() {}

void loop() {
static uint8_t last_to = 255;

if (!led.Update()) {
// when effect is done (Update() returns false),
// reconfigure fade effect using random values
auto new_from = last_to;
auto new_to = jled::rand8();
auto duration = 250 + jled::rand8() * 4;
last_to = new_to;
led.Fade(new_from, new_to, duration).Repeat(1);
}
}
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ default_envs = esp32
;src_dir = examples/user_func
;src_dir = examples/sequence
;src_dir = examples/custom_hal
src_dir = examples/pulse
;src_dir = examples/pulse
src_dir = examples/fade_from_to

[env:nanoatmega328]
platform = atmelavr
Expand Down

0 comments on commit 45f3dbe

Please sign in to comment.