Skip to content

Commit

Permalink
Merge pull request #227 from helgibbons/main
Browse files Browse the repository at this point in the history
Couple of festive examples for Plasma 2040
  • Loading branch information
Gadgetoid authored Dec 7, 2021
2 parents f96012a + 2aace8c commit ce1f8ad
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
45 changes: 45 additions & 0 deletions micropython/examples/plasma2040/alternating-blinkies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This super simple example sets up two alternating colours, great for festive lights!

import plasma
from plasma import plasma2040
import time

# Set how many LEDs you have
NUM_LEDS = 50

# Pick two hues from the colour wheel (from 0-360°, try https://www.cssscript.com/demo/hsv-hsl-color-wheel-picker-reinvented/ )
HUE_1 = 0
HUE_2 = 127

# Set up brightness (between 0 and 1)
BRIGHTNESS = 0.5

# Set up speed (wait time between colour changes, in seconds)
SPEED = 1

# Pick *one* LED type by uncommenting the relevant line below:

# APA102 / DotStar™ LEDs
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)

# WS2812 / NeoPixel™ LEDs
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)

# Start updating the LED strip
led_strip.start()

while True:
for i in range(NUM_LEDS):
# the if statements below use a modulo operation to identify the even and odd numbered LEDs
if (i % 2) == 0:
led_strip.set_hsv(i, HUE_1 / 360, 1.0, BRIGHTNESS)
else:
led_strip.set_hsv(i, HUE_2 / 360, 1.0, BRIGHTNESS)
time.sleep(SPEED)

for i in range(NUM_LEDS):
if (i % 2) == 0:
led_strip.set_hsv(i, HUE_2 / 360, 1.0, BRIGHTNESS)
else:
led_strip.set_hsv(i, HUE_1 / 360, 1.0, BRIGHTNESS)
time.sleep(SPEED)
42 changes: 42 additions & 0 deletions micropython/examples/plasma2040/random-blinkies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This simple example randomises LED colours and brightness for a subtly sparkly effect.

import plasma
from plasma import plasma2040
import time
# Random functions! randrange is for picking integers from a range, and uniform is for floats.
from random import randrange, uniform

# Set how many LEDs you have
NUM_LEDS = 50

# Pick what bits of the colour wheel to use (from 0-360°, try https://www.cssscript.com/demo/hsv-hsl-color-wheel-picker-reinvented/ )
HUE_START = 180
HUE_END = 260

# Set up brightness minimum and maximum (between 0.0 and 1.0)
BRIGHTNESS_MIN = 0.2
BRIGHTNESS_MAX = 0.7

# Set up speed (wait time between updates, in seconds.)
SPEED = 0.3

# Pick *one* LED type by uncommenting the relevant line below:

# APA102 / DotStar™ LEDs
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)

# WS2812 / NeoPixel™ LEDs
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)

# Start updating the LED strip
led_strip.start()

# Light up all the leds random colours and brightnesses from the specified ranges...
for i in range(NUM_LEDS):
led_strip.set_hsv(i, randrange(HUE_START, HUE_END) / 360, 1.0, uniform(BRIGHTNESS_MIN, BRIGHTNESS_MAX))

while True:
# ...and then update one random pixel at a time to keep things fresh and sparkly.
# Comment out the lines below if you want static lights.
led_strip.set_hsv(randrange(0, NUM_LEDS), randrange(HUE_START, HUE_END) / 360, 1.0, uniform(BRIGHTNESS_MIN, BRIGHTNESS_MAX))
time.sleep(SPEED)

0 comments on commit ce1f8ad

Please sign in to comment.