circuitplayground_pixels_simpletest.py
1 # CircuitPython demo - NeoPixel 2 3 import time 4 from adafruit_circuitplayground.express import cpx 5 6 # The number of pixels in the strip 7 numpix = 10 8 9 10 def wheel(pos): 11 # Input a value 0 to 255 to get a color value. 12 # The colours are a transition r - g - b - back to r. 13 if (pos < 0) or (pos > 255): 14 return (0, 0, 0) 15 if pos < 85: 16 return (int(pos * 3), int(255 - (pos*3)), 0) 17 if pos < 170: 18 pos -= 85 19 return (int(255 - pos*3), 0, int(pos*3)) 20 pos -= 170 21 return (0, int(pos*3), int(255 - pos*3)) 22 23 24 def rainbow_cycle(wait): 25 for j in range(255): 26 for i in range(cpx.pixels.n): 27 idx = int((i * 256 / len(cpx.pixels)) + j) 28 cpx.pixels[i] = wheel(idx & 255) 29 cpx.pixels.show() 30 time.sleep(wait) 31 32 33 cpx.pixels.auto_write = False 34 cpx.pixels.brightness = 0.3 35 while True: 36 rainbow_cycle(0.001) # rainbowcycle with 1ms delay per step