Skip to content

Commit

Permalink
Merge pull request #1272 from freefoote/patch-1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
barbudor authored Sep 6, 2023
2 parents cb4facc + 96fde0d commit 72986ff
Showing 1 changed file with 37 additions and 3 deletions.
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

0 comments on commit 72986ff

Please sign in to comment.