-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added experimental examples for Plasma 2040
- Loading branch information
1 parent
963aa32
commit fa536ef
Showing
6 changed files
with
215 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Plasma 2040 Micropython Examples <!-- omit in toc --> | ||
|
||
These are micropython examples for the Pimoroni [Plasma 2040](https://shop.pimoroni.com/products/plasma-2040), a RP2040-based driver board for addressable LED strips. | ||
|
||
- [Effect Examples](#effect-examples) | ||
- [Pulse Wave](#pulse-wave) | ||
- [Binary Counter](#binary-counter) | ||
- [Rainbow Wave](#rainbow-wave) | ||
|
||
|
||
## Effect Examples | ||
|
||
### Pulse Wave | ||
[effects/pulse_wave.py](effects/pulse_wave.py) | ||
|
||
Play a wave of pulses on Plasma 2040's strip output. | ||
This is an *experimental* feature, that can struggle when | ||
complex effects with high update rates are applied to many LEDs. | ||
|
||
|
||
### Binary Counter | ||
[effects/binary_counter.py](effects/binary_counter.py) | ||
|
||
Play a binary counter effect on Plasma 2040's strip output. | ||
This is an *experimental* feature, that can struggle when | ||
complex effects with high update rates are applied to many LEDs. | ||
|
||
|
||
### Rainbow Wave | ||
[effects/rainbow_wave.py](effects/rainbow_wave.py) | ||
|
||
Play a rainbow wave effect on Plasma 2040's strip output. | ||
This is an *experimental* feature, that can struggle when | ||
complex effects with high update rates are applied to many LEDs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import plasma | ||
from plasma import plasma2040 | ||
from picofx import StripPlayer | ||
from picofx.mono import BinaryCounterFX | ||
from pimoroni import Button | ||
|
||
""" | ||
Play a binary counter effect on Plasma 2040's strip output. | ||
This is an *experimental* feature, that can struggle when | ||
complex effects with high update rates are applied to many LEDs. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Constants | ||
NUM_LEDS = 60 # How many LEDs are on the connected Strip | ||
INTERVAL = 0.1 # The time (in seconds) between each increment of the binary counter | ||
UPDATES = 60 # How many times the LEDs and effects updated per second | ||
|
||
|
||
# Variables | ||
boot = Button(plasma2040.USER_SW) | ||
|
||
# Pick *one* LED type by uncommenting the relevant line below: | ||
|
||
# APA102 / DotStar™ LEDs | ||
# strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK) | ||
|
||
# WS2812 / NeoPixel™ LEDs | ||
strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT, | ||
color_order=plasma.COLOR_ORDER_RGB) | ||
|
||
# Create a new effect player to control the LED strip | ||
player = StripPlayer(strip, num_leds=NUM_LEDS) | ||
|
||
# Create a BinaryCounterFX effect | ||
binary = BinaryCounterFX(interval=INTERVAL) | ||
|
||
# Set up the binary counter effect to play, mirrored at the middle of the strip. | ||
player.effects = [ | ||
binary(i) for i in range(NUM_LEDS // 2) | ||
] + [ | ||
binary(NUM_LEDS // 2 - 1 - i) for i in range(NUM_LEDS // 2) | ||
] | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
strip.start(UPDATES) # Start updating the LED strip | ||
player.start(UPDATES) # Start the effects running, with a lower update rate than normal | ||
|
||
# Loop until the effect stops or the "Boot" button is pressed | ||
while player.is_running() and not boot.raw(): | ||
pass | ||
|
||
# Stop any running effects and turn off the LED strip | ||
finally: | ||
player.stop() | ||
strip.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import plasma | ||
from plasma import plasma2040 | ||
from picofx import StripPlayer | ||
from picofx.mono import PulseWaveFX | ||
from pimoroni import Button | ||
|
||
""" | ||
Play a wave of pulses on Plasma 2040's strip output. | ||
This is an *experimental* feature, that can struggle when | ||
complex effects with high update rates are applied to many LEDs. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Constants | ||
NUM_LEDS = 60 # How many LEDs are on the connected Strip | ||
SPEED = 0.2 # The speed to cycle the pulses at, with 1.0 being 1 second | ||
UPDATES = 30 # How many times the LEDs and effects updated per second | ||
|
||
|
||
# Variables | ||
boot = Button(plasma2040.USER_SW) | ||
|
||
# Pick *one* LED type by uncommenting the relevant line below: | ||
|
||
# APA102 / DotStar™ LEDs | ||
# strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK) | ||
|
||
# WS2812 / NeoPixel™ LEDs | ||
strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT, | ||
color_order=plasma.COLOR_ORDER_RGB) | ||
|
||
# Create a new effect player to control the LED strip | ||
player = StripPlayer(strip, num_leds=NUM_LEDS) | ||
|
||
# Create a PulseWaveFX effect | ||
wave = PulseWaveFX(speed=SPEED, length=NUM_LEDS) | ||
|
||
# Set up the wave effect to play, mirrored at the middle of the strip. | ||
# Each output has a different position along the wave, with the value being related to the effect's length | ||
player.effects = [wave(i) for i in range(NUM_LEDS)] | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
strip.start(UPDATES) # Start updating the LED strip | ||
player.start(UPDATES) # Start the effects running, with a lower update rate than normal | ||
|
||
# Loop until the effect stops or the "Boot" button is pressed | ||
while player.is_running() and not boot.raw(): | ||
pass | ||
|
||
# Stop any running effects and turn off the LED strip | ||
finally: | ||
player.stop() | ||
strip.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import plasma | ||
from plasma import plasma2040 | ||
from picofx import StripPlayer | ||
from picofx.colour import RainbowWaveFX | ||
from pimoroni import Button | ||
|
||
""" | ||
Play a rainbow wave effect on Plasma 2040's strip output. | ||
This is an *experimental* feature, that can struggle when | ||
complex effects with high update rates are applied to many LEDs. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Constants | ||
NUM_LEDS = 60 # How many LEDs are on the connected Strip | ||
SPEED = 0.2 # The speed to cycle the rainbow at, with 1.0 being 1 second | ||
UPDATES = 20 # How many times the LEDs and effects updated per second | ||
|
||
|
||
# Variables | ||
boot = Button(plasma2040.USER_SW) | ||
|
||
# Pick *one* LED type by uncommenting the relevant line below: | ||
|
||
# APA102 / DotStar™ LEDs | ||
# strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK) | ||
|
||
# WS2812 / NeoPixel™ LEDs | ||
strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT, | ||
color_order=plasma.COLOR_ORDER_RGB) | ||
|
||
# Create a new effect player to control the LED strip | ||
player = StripPlayer(strip, num_leds=NUM_LEDS) | ||
|
||
# Create a RainbowWaveFX effect | ||
rainbow = RainbowWaveFX(speed=SPEED, length=NUM_LEDS) | ||
|
||
# Set up the rainbow wave effect to play. | ||
# Each output has a different position along the wave, with the value being related to the effect's length | ||
player.effects = [rainbow(i) for i in range(NUM_LEDS)] | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
strip.start(UPDATES) # Start updating the LED strip | ||
player.start(UPDATES) # Start the effects running, with a lower update rate than normal | ||
|
||
# Loop until the effect stops or the "Boot" button is pressed | ||
while player.is_running() and not boot.raw(): | ||
pass | ||
|
||
# Stop any running effects and turn off the LED strip | ||
finally: | ||
player.stop() | ||
strip.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters