From e045cb9615227feb145ba965065325ff92a2cf3f Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 17 Aug 2021 13:25:46 +0100 Subject: [PATCH] Updated plasma mp examples to use user_sw and current sensing --- micropython/examples/plasma_2040/rainbow.py | 19 +++++++++++++++++-- .../plasma_2040/rgb-led-and-buttons.py | 8 ++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/micropython/examples/plasma_2040/rainbow.py b/micropython/examples/plasma_2040/rainbow.py index 89e93dc4..2e88281c 100644 --- a/micropython/examples/plasma_2040/rainbow.py +++ b/micropython/examples/plasma_2040/rainbow.py @@ -1,19 +1,34 @@ import plasma import time +# Import helper for Analog +from pimoroni import Analog + NUM_LEDS = 30 +UPDATES = 60 # WS2812 / NeoPixelâ„¢ LEDs led_strip = plasma.WS2812(NUM_LEDS, 0, 0, 15) # APA102 / DotStarâ„¢ LEDs -# led_strip = plasma.APA102(NUM_LEDS, 0, 0, 15, 14) +#led_strip = plasma.APA102(NUM_LEDS, 0, 0, 15, 14) + +# Set up the ADC for reading current +sense = Analog(plasma.PIN_CURRENT_SENSE, plasma.ADC_GAIN, plasma.SHUNT_RESISTOR) # Start updating the LED strip led_strip.start() +count = 0 # Make rainbows while True: t = time.ticks_ms() / 1000.0 / 5.0 for i in range(NUM_LEDS): led_strip.set_hsv(i, t + (i / NUM_LEDS)) - time.sleep(1.0 / 60) + + count += 1 + if count >= UPDATES: + # Display the current value once every second + print("Current =", sense.read_current(), "A") + count = 0 + + time.sleep(1.0 / UPDATES) diff --git a/micropython/examples/plasma_2040/rgb-led-and-buttons.py b/micropython/examples/plasma_2040/rgb-led-and-buttons.py index a6d4501e..f4efa456 100644 --- a/micropython/examples/plasma_2040/rgb-led-and-buttons.py +++ b/micropython/examples/plasma_2040/rgb-led-and-buttons.py @@ -1,18 +1,22 @@ import time # Import pin constants from plasma -from plasma import PIN_LED_R, PIN_LED_G, PIN_LED_B, PIN_BUTTON_A, PIN_BUTTON_B +from plasma import PIN_LED_R, PIN_LED_G, PIN_LED_B, PIN_USER_SW, PIN_BUTTON_A, PIN_BUTTON_B # Import helpers for RGB LEDs and Buttons from pimoroni import RGBLED, Button led = RGBLED(PIN_LED_R, PIN_LED_G, PIN_LED_B) -led.set_rgb(255, 0, 0) +led.set_rgb(0, 0, 0) +user_sw = Button(PIN_USER_SW) button_a = Button(PIN_BUTTON_A) button_b = Button(PIN_BUTTON_B) while True: + if user_sw.read(): + print("Pressed User SW - {}".format(time.ticks_ms())) + led.set_rgb(255, 0, 0) if button_a.read(): print("Pressed A - {}".format(time.ticks_ms())) led.set_rgb(0, 255, 0)