Categories
Classes Projects

Make a Color-Changing Silhouette Light

Onboard NeoPixels:
Random colors & using show()

import board
import neopixel
from time import sleep
import random

RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
PURPLE = (128, 0, 128)

NUM_LEDS = 10
PIXEL_PIN = board.D8

np = neopixel.NeoPixel(PIXEL_PIN, NUM_LEDS, brightness=0.1, auto_write=False)


def ColorShow():
for i in range(NUM_LEDS):
red = random.randint(0, 255)
green = random.randint(0, 255)
blue = random.randint(0, 255)
new_color = (red, green, blue)
np[i] = new_color
np.show()
return new_color


def ColorWheel(new_color):
for i in range(NUM_LEDS):
np[i] = new_color
np.show()
sleep(0.2)


while True:
print("Displaying ColorShow")
next = ColorShow()
sleep(0.5)

print("Displaying ColorWheel", next)
ColorWheel(next)
sleep(0.5)