From 3be7894aaf775878a181b9f562fe35ed6e94746d Mon Sep 17 00:00:00 2001 From: freefoote Date: Mon, 4 Sep 2023 16:54:50 +0800 Subject: [PATCH 1/2] Update Led Rainbow example to actually execute on a device. --- docs/Berry_Addressable-LED.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Berry_Addressable-LED.md b/docs/Berry_Addressable-LED.md index 20c1b554ff..3c82f72621 100644 --- a/docs/Berry_Addressable-LED.md +++ b/docs/Berry_Addressable-LED.md @@ -106,10 +106,10 @@ class Rainbow_stripes : Leds_animator var i = 0 while i < self.pixel_count # doing a loop rather than a `for` prevents from allocating a new object var col = self.palette[(self.cur_offset + i) % size(self.palette)] - strip.set_pixel_color(i, col, self.bri) # simulate the method call without GETMET + self.strip.set_pixel_color(i, col, self.bri) # simulate the method call without GETMET i += 1 end - strip.show() + self.strip.show() end end ``` @@ -117,7 +117,7 @@ end How to use: ``` python -var strip = Leds_matrix(5,5, gpio.pin(gpio.WS2812, 1)) +var strip = Leds(5,5, gpio.pin(gpio.WS2812, 1)) var r = Rainbow_stripes(strip, 1.0) r.start() ``` From 96fde0d6143b5d3ae172f2b398537a0b6aec7d6f Mon Sep 17 00:00:00 2001 From: freefoote Date: Mon, 4 Sep 2023 17:20:14 +0800 Subject: [PATCH 2/2] Added additional "Breathe" example. --- docs/Berry_Addressable-LED.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/Berry_Addressable-LED.md b/docs/Berry_Addressable-LED.md index 3c82f72621..fb6271c18d 100644 --- a/docs/Berry_Addressable-LED.md +++ b/docs/Berry_Addressable-LED.md @@ -122,6 +122,40 @@ var r = Rainbow_stripes(strip, 1.0) r.start() ``` +And here is another example that "breathes" the LED strip with a hardcoded colour: + +``` python +class Breathe : Leds_animator + var brightness + var colour + + # duration in seconds + def init(strip, duration) + super(self).init(strip) + self.brightness = 0 + self.colour = 0xFFFFFF + self.add_anim(animate.back_forth(def(v) self.brightness = v end, 0, 100, int(duration * 1000))) + end + + def animate() + var i = 0 + while i < self.pixel_count # doing a loop rather than a `for` prevents from allocating a new object + self.strip.set_pixel_color(i, self.colour, self.brightness) + i += 1 + end + self.strip.show() + end +end +``` + +And to use this one: + +``` python +var strip = Leds(5,5, gpio.pin(gpio.WS2812, 1)) +var r = Breathe(strip, 2.0) +r.start() +``` + ## Advanced features ### Hardware `RMT` channels