3.6. Exercise: Light Show#
Navigate to the MicroPython editor https://python.microbit.org/v/3. If you already have it open, then use that existing window or tab.
Connect your micro:bit using the instructions on the previous page
Enter the following code into the editor
from microbit import *
import neopixel
display.scroll("WARNING", wait=False, loop=True)
while True:
sleep(200)
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
RGB0is red,RGB1is blue,RGB2is green andRGB3is purple. Then after a short delayRGB0becomes purple,RGB1becomes blue and so on.
Solution
Solution is locked