Pretty Lights 1 - Lighting Groups Of Pixels

Lighting Groups Of Pixels

The functions in this first set are pretty basic. I use these as indicators when trying to get the robot to respond to its sensors.


from microbit import *
import neopixel

# Initialise neopixels
npix = neopixel.NeoPixel(pin13, 12)

# Define some colours
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
nocol = (0,0,0)

# light all neopixels with given colour
def LightAll(col):
    for pix in range(0, len(npix)):
        npix[pix] = col
    npix.show()
    return
    
# light neopixels on the left fin    
def LightLeft(col):
    for pix in range(0, 6):
        npix[pix] = col
    npix.show()
    return
    
# light neopixels on the right fin
def LightRight(col):
    for pix in range(6, 12):
        npix[pix] = col
    npix.show()
    return
    
    
while True:
    # All red
    LightAll(red)
    sleep(2000)
    # Clear all
    npix.clear()
    sleep(1000)
    # Light left pixels green
    LightLeft(green)
    # Light right pixels blue
    LightRight(blue)
    sleep(2000)
    # Clear left
    LightLeft(nocol)
    sleep(1000)
    # Clear right
    LightRight(nocol)
    sleep(1000)
Comments