Colour Wipe
A colour wipe is when you light each pixel one at a time with a
colour. A small delay is used between each lighting up neopixel so that
the colour seems to be wiped across the chain. There are 3 functions to
do this. The first wipes the colour according to the numerical order of
the neopixels. The other two wipe the colour from the back to the front
of the robot and vice versa.
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)
# Colour wipe functions def Wipe(col, delay): for pix in range(0, len(npix)): npix[pix] = col npix.show() sleep(delay) return
def WipeForward(col, delay): for pix in range(0, 6): npix[pix] = col npix[pix+6] = col npix.show() sleep(delay) return def WipeBackward(col, delay): for pix in range(11, 5,-1): npix[pix] = col npix[pix-6] = col npix.show() sleep(delay) return while True: Wipe(red, 100) sleep(1000) Wipe(green, 100) sleep(1000) Wipe(blue, 100) sleep(1000) WipeForward(red, 100) sleep(1000) WipeForward(green, 100) sleep(1000) WipeForward(blue, 100) sleep(1000) WipeBackward(red, 100) sleep(1000) WipeBackward(green, 100) sleep(1000) WipeBackward(blue, 100) sleep(1000) |
|