Exercise: Light Show

3.6. Exercise: Light Show#

  1. Navigate to the MicroPython editor https://python.microbit.org/v/3. If you already have it open, then use that existing window or tab.

  2. Connect your micro:bit using the instructions on the previous page

  3. Enter the following code into the editor

from microbit import *
import neopixel

display.scroll("WARNING", wait=False, loop=True)

while True:
    sleep(200)
  1. Flash the code to your micro:bit.

If you get stuck ask a peer or your teacher for help!

Question 1

Extend the code so that:

  • the front driving lights alternate

Solution
from microbit import *

display.scroll("WARNING", wait=False, loop=True)

state = 1

while True:
    pin8.write_digital(state)
    pin12.write_digital(1-state)
    sleep(200)
    state = 1-state
Question 2

Extend the code so that:

  • the RGB LEDs cycle together between three colours of your choice

Solution

Solution is locked

Question 3

Extend your code so that:

  • the RGB LEDs colours rotate through four colours of your choice. For example RGB0 is red, RGB1 is blue, RGB2 is green and RGB3 is purple. Then after a short delay RGB0 becomes purple, RGB1 becomes blue and so on.

Solution

Solution is locked