Instructions

Linker Kit Base Set Raspberry Pi
Veröffentlicht: 09.10.2018 Copyright by Maker Factory 9
3. DIE RGB-LED
def wheel(pos):
"""Generate rainbow colors across 0-255 posions."""
if pos < 85:
return Color(pos * 3, 255 - pos * 3, 0)
elif pos < 170:
pos -= 85
return Color(255 - pos * 3, 0, pos * 3)
else:
pos -= 170
return Color(0, pos * 3, 255 - pos * 3)
def rainbow(strip, wait_ms=20, iteraons=1):
"""Draw rainbow that fades across all pixels at once."""
for j in range(256*iteraons):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((i+j) & 255))
strip.show()
me.sleep(wait_ms/1000.0)
def rainbowCycle(strip, wait_ms=20, iteraons=5):
"""Draw rainbow that uniformly distributes itself across all pixels."""
for j in range(256*iteraons):
for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((int(i * 256 / strip.numPixels()) + j) & 255))
strip.show()
me.sleep(wait_ms/1000.0)
def theaterChaseRainbow(strip, wait_ms=50):
"""Rainbow movie theater light style chaser animaon."""
for j in range(256):
for q in range(3):
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i+q, wheel((i+j) % 255))
strip.show()
me.sleep(wait_ms/1000.0)
for i in range(0, strip.numPixels(), 3):
strip.setPixelColor(i+q, 0)
Beispielcode fortgeführt: