1- <table ><tr ><td >
2- <b >Preferring Python?</b > I just released <a href =" https://github.com/jandelgado/jled-circuitpython " >jled-circuitpython</a >,
1+ <table ><tr ><td >
2+ <b >Preferring Python?</b > I just released <a href =" https://github.com/jandelgado/jled-circuitpython " >jled-circuitpython</a >,
33a JLed implementation for CircuitPython and MicroPython.
44</td ></tr ></table >
55
@@ -91,8 +91,8 @@ void loop() {
9191 * [ Arduino framework] ( #arduino-framework )
9292 * [ Raspberry Pi Pico] ( #raspberry-pi-pico )
9393* [ Example sketches] ( #example-sketches )
94- * [ PlatformIO] ( #platformio-1 )
95- * [ Arduino IDE] ( #arduino-ide-1 )
94+ * [ Building examples with PlatformIO] ( #building-examples-with-platformio )
95+ * [ Building examples with the Arduino IDE] ( #building-examples-with-the- arduino-ide )
9696* [ Extending] ( #extending )
9797 * [ Support new hardware] ( #support-new-hardware )
9898* [ Unit tests] ( #unit-tests )
@@ -194,9 +194,9 @@ Use the `Set(uint8_t brightness, uint16_t period=1)` method to set the
194194brightness to the given value, i.e., ` Set(255) ` is equivalent to calling ` On() `
195195and ` Set(0) ` is equivalent to calling ` Off() ` .
196196
197- Technically, ` Set ` , ` On ` and ` Off ` are effects with a default period of 1ms, that
197+ Technically, ` Set ` , ` On ` and ` Off ` are effects with a default period of 1ms, that
198198set the brightness to a constant value. Specifying a different period has an
199- effect on when the ` Update() ` method will be done updating the effect and
199+ effect on when the ` Update() ` method will be done updating the effect and
200200return false (like for any other effects). This is important when for example
201201in a ` JLedSequence ` the LED should stay on for a given amount of time.
202202
@@ -268,25 +268,25 @@ auto led = JLed(13).Breathe(500, 1000, 500).DelayAfter(1000).Forever();
268268
269269#### Candle
270270
271- In candle mode, the random flickering of a candle or fire is simulated.
271+ In candle mode, the random flickering of a candle or fire is simulated.
272272The builder method has the following signature:
273273 ` Candle(uint8_t speed, uint8_t jitter, uin16_t period) `
274274
275- * ` speed ` - controls the speed of the effect. 0 for fastest, increasing speed
275+ * ` speed ` - controls the speed of the effect. 0 for fastest, increasing speed
276276 divides into halve per increment. The default value is 7.
277277* ` jitter ` - the amount of jittering. 0 none (constant on), 255 maximum. Default
278278 value is 15.
279279* ` period ` - Period of effect in ms. The default value is 65535 ms.
280280
281281The default settings simulate a candle. For a fire effect for example use
282- call the method with ` Candle(5 /*speed*/, 100 /* jitter*/) ` .
282+ call the method with ` Candle(5 /*speed*/, 100 /* jitter*/) ` .
283283
284284##### Candle example
285285
286286``` c++
287287#include < jled.h>
288288
289- // Candle on LED pin 13 (PWM capable).
289+ // Candle on LED pin 13 (PWM capable).
290290auto led = JLed(13 ).Candle();
291291
292292void setup () { }
@@ -363,7 +363,7 @@ two methods:
363363 as an unsigned byte, where 0 means LED off and 255 means full brightness.
364364* ` uint16_t Period() const ` - period of the effect.
365365
366- All time values are specified in milliseconds.
366+ All time values are specified in milliseconds.
367367
368368The [ user_func] ( examples/user_func ) example demonstrates a simple user provided
369369brightness function, while the [ morse] ( examples/morse ) example shows how a more
@@ -410,10 +410,29 @@ specified by `DelayAfter()` method.
410410
411411##### Update
412412
413- Call `Update()` or `Update(uint32_t t)` periodically to update the state of the
414- LED. `Update` returns `true` if the effect is active, and `false` when it
415- finished. `Update()` is a shortcut to call `Update(uint32_t t)` with the
416- current time.
413+ Call `Update(int16_t *pLast=nullptr)` or `Update(uint32_t t, int16_t *pLast=nullptr)`
414+ to periodically update the state of the LED.
415+
416+ `Update` returns `true`, if the effect is active, or `false` when it finished.
417+ `Update()` is a shortcut to call `Update(uint32_t t)` with the current time in
418+ milliseconds.
419+
420+ To obtain the value of the last written brightness value (after applying min-
421+ and max-brightness transformations), pass an additional optional pointer
422+ `*pLast` , where this value will be stored, when it was written. Example:
423+
424+ ```c++
425+ int16_t lastVal = -1;
426+ led.Update(&lastVal);
427+ if (lastVal != -1) {
428+ // the LED was updated with the brightness value now stored in lastVal
429+ ...
430+ }
431+ ```
432+
433+ Most of the time just calling ` Update() ` without any parameters is what you want.
434+
435+ See [ last_brightness] ( examples/last_brightness ) example for a working example.
417436
418437##### IsRunning
419438
@@ -453,16 +472,16 @@ will be inverted by JLed (i.e., instead of x, the value of 255-x will be set).
453472
454473##### Minimum- and Maximum brightness level
455474
456- The ` MaxBrightness(uint8_t level) ` method is used to set the maximum brightness
457- level of the LED. A level of 255 (the default) is full brightness, while 0
475+ The ` MaxBrightness(uint8_t level) ` method is used to set the maximum brightness
476+ level of the LED. A level of 255 (the default) is full brightness, while 0
458477effectively turns the LED off. In the same way, the ` MinBrightness(uint8_t level) `
459478method sets the minimum brightness level. The default minimum level is 0. If
460479minimum or maximum brightness levels are set, the output value is scaled to be
461480within the interval defined by ` [minimum brightness, maximum brightness] ` : a
462481value of 0 will be mapped to the minimum brightness level, a value of 255 will
463482be mapped to the maximum brightness level.
464483
465- The ` uint_8 MaxBrightness() const ` method returns the current maximum
484+ The ` uint_8 MaxBrightness() const ` method returns the current maximum
466485brightness level. ` uint8_t MinBrightness() const ` returns the current minimum
467486brightness level.
468487
@@ -500,10 +519,10 @@ The `JLedSequence` provides the following methods:
500519 else ` false ` .
501520* Use the ` Repeat(n) ` method to specify the number of repetitions. The default
502521 value is 1 repetition. The ` Forever() ` methods sets to repeat the sequence
503- forever.
504- * ` Stop() ` - turns off all ` JLed ` objects controlled by the sequence and
522+ forever.
523+ * ` Stop() ` - turns off all ` JLed ` objects controlled by the sequence and
505524 stops the sequence. Further calls to ` Update() ` will have no effect.
506- * ` Reset() ` - Resets all ` JLed ` objects controlled by the sequence and
525+ * ` Reset() ` - Resets all ` JLed ` objects controlled by the sequence and
507526 the sequence, resulting in a start-over.
508527
509528## Framework notes
@@ -518,7 +537,7 @@ framework:
518537platform =ststm32
519538board = nucleo_f401re
520539framework = mbed
521- build_flags = -Isrc
540+ build_flags = -Isrc
522541src_filter = +<../../src/> +<./>
523542upload_protocol =stlink
524543```
@@ -570,8 +589,8 @@ so it should be avoided and is normally not necessary.
570589For completeness, the full signature of the Esp32Hal constructor is
571590
572591```
573- Esp32Hal(PinType pin,
574- int chan = kAutoSelectChan,
592+ Esp32Hal(PinType pin,
593+ int chan = kAutoSelectChan,
575594 uint16_t freq = 5000,
576595 ledc_timer_t timer = LEDC_TIMER_0)
577596```
@@ -600,9 +619,14 @@ necessary to upload sketches to the microcontroller.
600619
601620### Raspberry Pi Pico
602621
603- When using JLed on a Raspberry Pi Pico, the Pico-SDK and tools must be
604- installed. The Pico supports up to 16 PWM channels in parallel. See
605- the [pico-demo](examples/raspi_pico) for an example and build instructions.
622+ When using JLed on a Raspberry Pi Pico, the Pico-SDK and tools can be
623+ used. The Pico supports up to 16 PWM channels in parallel. See
624+ the [pico-demo](examples/raspi_pico) for an example and build instructions when
625+ the Pico-SDK is used.
626+
627+ A probably easier approach is to use the Arduino platform. See
628+ [platformio.ini](platformio.ini) for details (look for
629+ ` env:raspberrypi_pico_w ` , which targets the Raspberry Pi Pico W.
606630
607631## Example sketches
608632
@@ -621,6 +645,7 @@ Example sketches are provided in the [examples](examples/) directory.
621645* [ Controlling multiple LEDs sequentially] ( examples/sequence )
622646* [ Simple User provided effect] ( examples/user_func )
623647* [ Morsecode example] ( examples/morse )
648+ * [ Last brightness value example] ( examples/last_brightness )
624649* [ Custom HAL example] ( examples/custom_hal )
625650* [ Custom PCA9685 HAL] ( https://github.com/jandelgado/jled-pca9685-hal )
626651* [ Dynamically switch sequences] ( https://github.com/jandelgado/jled-example-switch-sequence )
@@ -629,9 +654,9 @@ Example sketches are provided in the [examples](examples/) directory.
629654* [ ESP32 ESP-IDF example] ( https://github.com/jandelgado/jled-esp-idf-example )
630655* [ ESP32 ESP-IDF PlatformIO example] ( https://github.com/jandelgado/jled-esp-idf-platformio-example )
631656
632- ### PlatformIO
657+ ### Building examples with PlatformIO
633658
634- To build an example using [ the PlatformIO ide] ( http://platformio.org/ ) ,
659+ To build an example using [ the PlatformIO ide] ( http://platformio.org/ ) ,
635660uncomment the example to be built in the [ platformio.ini] ( platformio.ini )
636661project file, e.g.:
637662
@@ -642,7 +667,7 @@ src_dir = examples/hello
642667; src_dir = examples/breathe
643668```
644669
645- ### Arduino IDE
670+ ### Building examples with the Arduino IDE
646671
647672To build an example sketch in the Arduino IDE, select an example from
648673the ` File ` > ` Examples ` > ` JLed ` menu.
@@ -670,8 +695,8 @@ the host-based provided unit tests [is provided here](test/README.md).
670695* add code
671696* add [ unit test(s)] ( test/ )
672697* add [ documentation] ( README.md )
673- * make sure the cpp [ linter] ( https://github.com/cpplint/cpplint ) does not
674- report any problems (run ` make lint ` ). Hint: use ` clang-format ` with the
698+ * make sure the cpp [ linter] ( https://github.com/cpplint/cpplint ) does not
699+ report any problems (run ` make lint ` ). Hint: use ` clang-format ` with the
675700 provided [ settings] ( .clang-format )
676701* commit changes
677702* submit a PR
0 commit comments