Plasma 2350: new examples
This commit is contained in:
parent
c19c7ac4ac
commit
5ab5face89
@ -0,0 +1,57 @@
|
||||
import plasma
|
||||
from plasma import plasma2040
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_trackball import BreakoutTrackball
|
||||
|
||||
# SDA and SCL pins for the Tiny 2350 QW/ST connector
|
||||
PINS_PLASMA_2350 = {"sda": 20, "scl": 21, "baudrate": 100000}
|
||||
|
||||
# Create an I2C instance and setup the trackball breakout
|
||||
i2c = PimoroniI2C(**PINS_PLASMA_2350)
|
||||
trackball = BreakoutTrackball(i2c)
|
||||
|
||||
# Set how many LEDs you have
|
||||
NUM_LEDS = 100
|
||||
|
||||
# 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, rgbw=True)
|
||||
|
||||
# Start updating the LED strip
|
||||
led_strip.start()
|
||||
|
||||
# Clear any previously lit LEDs
|
||||
led_strip.clear()
|
||||
|
||||
position = 0
|
||||
sensitivity = 1
|
||||
hue = 0.0
|
||||
|
||||
while True:
|
||||
|
||||
# Read the trackball data
|
||||
state = trackball.read()
|
||||
|
||||
# Increase/Decrease the number of LEDs lit when moving the trackball Up/Down
|
||||
if state[BreakoutTrackball.UP] > sensitivity:
|
||||
if position < NUM_LEDS:
|
||||
position += 1
|
||||
if state[BreakoutTrackball.DOWN] > sensitivity:
|
||||
if position > 0:
|
||||
position -= 1
|
||||
|
||||
# Change the hue when moving the trackball Left/Right
|
||||
if state[BreakoutTrackball.LEFT] > sensitivity:
|
||||
hue += 0.02
|
||||
if state[BreakoutTrackball.RIGHT] > sensitivity:
|
||||
hue -= 0.02
|
||||
|
||||
# Set the LEDs
|
||||
for i in range(position):
|
||||
led_strip.set_hsv(i, hue, 1.0, 1.0)
|
||||
|
||||
# Clear the LEDs we're not using at the moment
|
||||
for i in range(position, NUM_LEDS):
|
||||
led_strip.set_rgb(i, 0, 0, 0)
|
||||
16
micropython/examples/plasma_2350/buttons.py
Normal file
16
micropython/examples/plasma_2350/buttons.py
Normal file
@ -0,0 +1,16 @@
|
||||
import time
|
||||
import machine
|
||||
|
||||
# Setup for the button pins
|
||||
user_button = machine.Pin(22, machine.Pin.IN)
|
||||
a_button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
|
||||
|
||||
while True:
|
||||
|
||||
if user_button.value() == 0:
|
||||
print("USER BUTTON PRESSED!")
|
||||
|
||||
if a_button.value() == 0:
|
||||
print("A BUTTON PRESSED!")
|
||||
|
||||
time.sleep(0.2)
|
||||
27
micropython/examples/plasma_2350/rainbow.py
Normal file
27
micropython/examples/plasma_2350/rainbow.py
Normal file
@ -0,0 +1,27 @@
|
||||
import plasma
|
||||
from plasma import plasma2040
|
||||
import time
|
||||
|
||||
# Set how many LEDs you have
|
||||
NUM_LEDS = 50
|
||||
|
||||
# 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()
|
||||
|
||||
offset = 0.0
|
||||
|
||||
while True:
|
||||
|
||||
offset += float(10) / 2000.0
|
||||
|
||||
for i in range(NUM_LEDS):
|
||||
hue = float(i) / NUM_LEDS
|
||||
led_strip.set_hsv(i, offset, 1.0, 1.0)
|
||||
|
||||
time.sleep(1.0 / 60)
|
||||
15
micropython/examples/plasma_2350/rgb_led.py
Normal file
15
micropython/examples/plasma_2350/rgb_led.py
Normal file
@ -0,0 +1,15 @@
|
||||
from pimoroni import RGBLED
|
||||
from time import sleep
|
||||
|
||||
# Setup the RGB Led
|
||||
led = RGBLED(16, 17, 18)
|
||||
|
||||
# Cycle through RGB
|
||||
|
||||
while True:
|
||||
led.set_rgb(255, 0, 0)
|
||||
sleep(1)
|
||||
led.set_rgb(0, 255, 0)
|
||||
sleep(1)
|
||||
led.set_rgb(0, 0, 255)
|
||||
sleep(1)
|
||||
22
micropython/examples/plasma_2350/single_colour.py
Normal file
22
micropython/examples/plasma_2350/single_colour.py
Normal file
@ -0,0 +1,22 @@
|
||||
import plasma
|
||||
from plasma import plasma2040
|
||||
|
||||
# Set how many LEDs you have
|
||||
NUM_LEDS = 50
|
||||
|
||||
# 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()
|
||||
|
||||
# Set each LED in the strip
|
||||
for i in range(NUM_LEDS):
|
||||
led_strip.set_rgb(i, 100, 0, 100)
|
||||
|
||||
# We've told the LEDs which colour to display and now we just want to keep the program running!
|
||||
while True:
|
||||
pass
|
||||
Loading…
Reference in New Issue
Block a user