From 963702a6e5b7becc4c8334698c192c525a5d7990 Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:11:42 +0000 Subject: [PATCH] add pulse example --- micropython/examples/plasma_stick/pulse.py | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 micropython/examples/plasma_stick/pulse.py diff --git a/micropython/examples/plasma_stick/pulse.py b/micropython/examples/plasma_stick/pulse.py new file mode 100644 index 00000000..99ffba1a --- /dev/null +++ b/micropython/examples/plasma_stick/pulse.py @@ -0,0 +1,42 @@ +import time +import plasma +from plasma import plasma_stick +from math import sin + +""" +Simple pulsing effect generated using a sine wave. +""" + +# Set how many LEDs you have +NUM_LEDS = 50 + +# we're using HSV colours in this example - find more at https://colorpicker.me/ +# to convert a hue that's in degrees, divide it by 360 +COLOUR = 0.5 + +# set up the WS2812 / NeoPixelâ„¢ LEDs +led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma_stick.DAT, color_order=plasma.COLOR_ORDER_RGB) + +# start updating the LED strip +led_strip.start() + +offset = 0 + +while True: + # use a sine wave to set the brightness + for i in range(NUM_LEDS): + led_strip.set_hsv(i, COLOUR, 1.0, sin(offset)) + offset += 0.002 + +# # our sine wave goes between -1.0 and 1.0 - this means the LEDs will be off half the time +# # this formula forces the brightness to be between 0.0 and 1.0 +# for i in range(NUM_LEDS): +# led_strip.set_hsv(i, COLOUR, 1.0, (1 + sin(offset)) / 2) +# offset += 0.002 + +# # adjust the saturation instead of the brightness/value +# for i in range(NUM_LEDS): +# led_strip.set_hsv(i, COLOUR, (1 + sin(offset)) / 2, 0.8) +# offset += 0.002 + +