Updated plasma mp examples to use user_sw and current sensing
This commit is contained in:
parent
5a911ad46e
commit
e045cb9615
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue