Last active
January 21, 2017 10:22
-
-
Save SteveAmor/96422ea08891919224d67a2950a1315d to your computer and use it in GitHub Desktop.
Neopixels with Microbit MU refactoring
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
# Initial code | |
from microbit import * | |
import neopixel | |
np = neopixel.NeoPixel(pin0,16) | |
red = (64,0,0) | |
green = (0,64,0) | |
blue = (0,0,64) | |
while True: | |
for pixel_id in range(0, len(np)): | |
np[pixel_id] = (red) | |
np.show() | |
sleep(10) | |
for pixel_id in range(0, len(np)): | |
np[pixel_id] = (green) | |
np.show() | |
sleep(10) | |
for pixel_id in range(0, len(np)): | |
np[pixel_id] = (blue) | |
np.show() | |
sleep(10) | |
# Refactored code | |
from microbit import * | |
import neopixel | |
np = neopixel.NeoPixel(pin0,16) | |
red = (64,0,0) | |
green = (0,64,0) | |
blue = (0,0,64) | |
def illuminate(colour): | |
for pixel_id in range(0, len(np)): | |
np[pixel_id] = (colour) | |
np.show() | |
sleep(20) | |
while True: | |
illuminate(red) | |
illuminate(green) | |
illuminate(blue) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment