Last active
August 9, 2016 23:48
-
-
Save cefn/a9b6ca20bae1d2be85af67044ed6cc90 to your computer and use it in GitHub Desktop.
Reference code for driving the microbit neopixel library through a rainbow effect
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
from microbit import * | |
import neopixel | |
# Setup the Neopixel strip on pin0 with a length of 8 pixels | |
np = neopixel.NeoPixel(pin0, 8) | |
def wheel(wheelByte): | |
wheelByte = 255 - wheelByte | |
if wheelByte < 85: | |
return (255 - wheelByte * 3, 0, wheelByte * 3) | |
if wheelByte < 170: | |
wheelByte = wheelByte - 85 | |
return (0, wheelByte * 3, 255 - wheelByte * 3) | |
wheelByte = wheelByte - 170 | |
return (wheelByte * 3, 255 - wheelByte * 3, 0) | |
wheelPos = 0 | |
while True: | |
#Iterate over each LED in the strip | |
for pixel_id in range(0, len(np)): | |
# Assign the current LED a color value from the rainbow sequence, with current offset | |
np[pixel_id] =wheel((wheelPos + pixel_id) % 255) | |
# Display the current pixel data on the Neopixel strip | |
np.show() | |
wheelPos = (wheelPos + 1) % 255 | |
sleep(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sleep(100) is a mistake, as that's in seconds (by contrast with sleep_ms(100))