From 5ab5face89bf471bfc3b340594263fda1fd4e1ef Mon Sep 17 00:00:00 2001 From: thirdr Date: Fri, 9 Aug 2024 13:43:49 +0100 Subject: [PATCH] Plasma 2350: new examples --- .../breakouts/trackball-breakout.py | 57 +++++++++++++++++++ micropython/examples/plasma_2350/buttons.py | 16 ++++++ micropython/examples/plasma_2350/rainbow.py | 27 +++++++++ micropython/examples/plasma_2350/rgb_led.py | 15 +++++ .../examples/plasma_2350/single_colour.py | 22 +++++++ 5 files changed, 137 insertions(+) create mode 100644 micropython/examples/plasma_2350/breakouts/trackball-breakout.py create mode 100644 micropython/examples/plasma_2350/buttons.py create mode 100644 micropython/examples/plasma_2350/rainbow.py create mode 100644 micropython/examples/plasma_2350/rgb_led.py create mode 100644 micropython/examples/plasma_2350/single_colour.py diff --git a/micropython/examples/plasma_2350/breakouts/trackball-breakout.py b/micropython/examples/plasma_2350/breakouts/trackball-breakout.py new file mode 100644 index 0000000..c75b817 --- /dev/null +++ b/micropython/examples/plasma_2350/breakouts/trackball-breakout.py @@ -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) diff --git a/micropython/examples/plasma_2350/buttons.py b/micropython/examples/plasma_2350/buttons.py new file mode 100644 index 0000000..7895798 --- /dev/null +++ b/micropython/examples/plasma_2350/buttons.py @@ -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) diff --git a/micropython/examples/plasma_2350/rainbow.py b/micropython/examples/plasma_2350/rainbow.py new file mode 100644 index 0000000..83f9eea --- /dev/null +++ b/micropython/examples/plasma_2350/rainbow.py @@ -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) diff --git a/micropython/examples/plasma_2350/rgb_led.py b/micropython/examples/plasma_2350/rgb_led.py new file mode 100644 index 0000000..88195fe --- /dev/null +++ b/micropython/examples/plasma_2350/rgb_led.py @@ -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) diff --git a/micropython/examples/plasma_2350/single_colour.py b/micropython/examples/plasma_2350/single_colour.py new file mode 100644 index 0000000..0566c99 --- /dev/null +++ b/micropython/examples/plasma_2350/single_colour.py @@ -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