import machine
import neopixel
import time
NUM_LEDS = 3
PIN_NUM = 4 # GP0
# Setup
pin = machine.Pin(PIN_NUM)
np = neopixel.NeoPixel(pin, NUM_LEDS)
# Farben setzen
def show_colors():
np[0] = (255, 0, 0) # Rot
np[1] = (0, 255, 0) # Grün
np[2] = (0, 0, 255) # Blau
np.write()
def wheel(pos):
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(delay=0.1):
while True:
for j in range(256):
for i in range(NUM_LEDS):
pixel_index = (i * 256 // NUM_LEDS + j) & 255
np[i] = wheel(pixel_index)
np.write()
time.sleep(delay)
# Lauflicht
def chase(delay=0.2):
while True:
for i in range(NUM_LEDS):
np[i] = (255, 255, 255)
np.write()
time.sleep(delay)
np[i] = (0, 0, 0)
# Farben einmal anzeigen
show_colors()
time.sleep(2)
# Dann Lauflicht starten
#chase()
rainbow()