Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
126 lines (98 sloc) 2.68 KB
 # CircuitPlaygroundExpress_NeoPixel import time import board import neopixel pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.2) pixels.fill((0, 0, 0)) pixels.show() # choose which demos to play # 1 means play, 0 means don't! simpleCircleDemo = 1 flashDemo = 1 rainbowDemo = 1 rainbowCycleDemo = 1 def wheel(pos): # Input a value 0 to 255 to get a color value. # The colours are a transition r - g - b - back to r. if pos < 85: return (int(pos * 3), int(255 - (pos * 3)), 0) elif pos < 170: pos -= 85 return (int(255 - (pos * 3)), 0, int(pos * 3)) else: pos -= 170 return (0, int(pos * 3), int(255 - pos * 3)) def rainbow_cycle(wait): for j in range(255): for i in range(len(pixels)): idx = int((i * 256 / len(pixels)) + j * 10) pixels[i] = wheel(idx & 255) pixels.show() time.sleep(wait) def rainbow(wait): for j in range(255): for i in range(len(pixels)): idx = int(i + j) pixels[i] = wheel(idx & 255) pixels.show() time.sleep(wait) def simpleCircle(wait): RED = 0x100000 # (0x10, 0, 0) also works YELLOW = (0x10, 0x10, 0) GREEN = (0, 0x10, 0) AQUA = (0, 0x10, 0x10) BLUE = (0, 0, 0x10) PURPLE = (0x10, 0, 0x10) BLACK = (0, 0, 0) for i in range(len(pixels)): pixels[i] = RED time.sleep(wait) time.sleep(1) for i in range(len(pixels)): pixels[i] = YELLOW time.sleep(wait) time.sleep(1) for i in range(len(pixels)): pixels[i] = GREEN time.sleep(wait) time.sleep(1) for i in range(len(pixels)): pixels[i] = AQUA time.sleep(wait) time.sleep(1) for i in range(len(pixels)): pixels[i] = BLUE time.sleep(wait) time.sleep(1) for i in range(len(pixels)): pixels[i] = PURPLE time.sleep(wait) time.sleep(1) for i in range(len(pixels)): pixels[i] = BLACK time.sleep(wait) time.sleep(1) while True: if simpleCircleDemo: print('Simple Circle Demo') simpleCircle(.05) if flashDemo: # this will play if flashDemo = 1 up above print('Flash Demo') pixels.fill((255, 0, 0)) pixels.show() time.sleep(.25) pixels.fill((0, 255, 0)) pixels.show() time.sleep(.25) pixels.fill((0, 0, 255)) pixels.show() time.sleep(.25) pixels.fill((255, 255, 255)) pixels.show() time.sleep(.25) if rainbowDemo: print('Rainbow Demo') rainbow(.001) if rainbowCycleDemo: print('Rainbow Cycle Demo') rainbow_cycle(.001)
You can’t perform that action at this time.