Skip to content

Instantly share code, notes, and snippets.

@SteveAmor
Last active January 21, 2017 10:22
Show Gist options
  • Save SteveAmor/96422ea08891919224d67a2950a1315d to your computer and use it in GitHub Desktop.
Save SteveAmor/96422ea08891919224d67a2950a1315d to your computer and use it in GitHub Desktop.
Neopixels with Microbit MU refactoring
# 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