-
-
Save chardane/874d2597a331d23fbd6e592e95c50aa9 to your computer and use it in GitHub Desktop.
Rainbow Animation from Adafruit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import board | |
import neopixel | |
pixel_pin = board.D2 | |
num_pixels = 12 | |
order = neopixel.GRB | |
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False, pixel_order=order) | |
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 < 0 or pos > 255: | |
return (0, 0, 0) | |
if pos < 85: | |
return (255 - pos * 3, pos * 3, 0) | |
if pos < 170: | |
pos -= 85 | |
return (0, 255 - pos * 3, pos * 3) | |
pos -= 170 | |
return (pos * 3, 0, 255 - pos * 3) | |
def rainbow_cycle(wait): | |
for j in range(255): | |
for i in range(num_pixels): | |
rc_index = (i * 256 // num_pixels) + j | |
pixels[i] = wheel(rc_index & 255) | |
pixels.show() | |
time.sleep(wait) | |
while True: | |
rainbow_cycle(0) # Increase the number to slow down the rainbow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment