/ NeoPixel_Punk_Collar / code.py
code.py
1 # SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 from rainbowio import colorwheel 7 import board 8 import neopixel 9 from digitalio import DigitalInOut, Direction 10 11 pixpin = board.D1 12 numpix = 5 13 14 led = DigitalInOut(board.D13) 15 led.direction = Direction.OUTPUT 16 17 strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=True) 18 19 20 def colorWipe(color, wait): 21 for j in range(len(strip)): 22 strip[j] = (color) 23 time.sleep(wait) 24 25 26 def rainbow_cycle(wait): 27 for j in range(255): 28 for i in range(len(strip)): 29 idx = int((i * 256 / len(strip)) + j) 30 strip[i] = colorwheel(idx & 255) 31 time.sleep(wait) 32 33 34 def rainbow(wait): 35 for j in range(255): 36 for i in range(len(strip)): 37 idx = int(i + j) 38 strip[i] = colorwheel(idx & 255) 39 time.sleep(wait) 40 41 42 while True: 43 colorWipe((255, 0, 0), .1) # red and delay 44 colorWipe((0, 255, 0), .1) # green and delay 45 colorWipe((0, 0, 255), .1) # blue and delay 46 47 rainbow(0.05) 48 rainbow_cycle(0.05)