From 80ee99748fd48636bc965f4823b734388bd5b963 Mon Sep 17 00:00:00 2001 From: Greg Smith Date: Tue, 7 Jun 2022 19:56:08 -0400 Subject: [PATCH] add examples/set_range.py --- examples/set_range.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/set_range.py diff --git a/examples/set_range.py b/examples/set_range.py new file mode 100644 index 0000000..bf71141 --- /dev/null +++ b/examples/set_range.py @@ -0,0 +1,40 @@ +# Example showing use of 'slice setting' +import time +from neopixel import Neopixel + + +numpix = 60 +K = 3 + +strip = Neopixel(numpix, 0, 0, "GRB") +red = (255, 0, 0) +green = (0, 255, 0) +blue = (0, 0, 255) + +# set the first K to red, next K to green, next K to blue; +# and the rest to R,G,B,R,B ... and then spin it. + +# reduce K, if numpix is < K*3+1 +K = min(K,(numpix-1)//3) + +strip.brightness(80) + +strip[:] = blue # all to blue first... +# now fill in the red & green... +strip[:K] = red +strip[K:2*K] = green +strip[3*K::3] = red +strip[3*K+1::3] = green + +strip.show() + +# show it for 5 seconds... +time.sleep(5.0) + +# spin it... + +while(True): + strip.rotate_right() + strip.show() + time.sleep(0.5) +