Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated WS2812 Berry Docs - the original examples had a compile error that prevented them from running. In the process, I've also added a second example. #1272

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions docs/Berry_Addressable-LED.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,56 @@ 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
```

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()
```

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
Expand Down