4. Maqueen headlights

The maqueen buggy has two red headlights.

4.1. Set up buggy headlights

class MaqueenHeadLights
Set up the buggy’s headlights for use.
Use headlights = maqueen.MaqueenHeadLights() to use the buggy’s headlights.
The code below imports the maqueen module and sets up the headlights.
from microbit import *
import maqueen


headlights = maqueen.MaqueenHeadLights()

4.2. set_headlight

set_headlight(headlight='left', on=1)
Turn the red headlights on or off individually.
headlight is ‘left’ or ‘right’. Default is ‘left’.
on is 1 to turn on the headlight or 0 to turn off the headlight. Default is 1.
The code below turns on the left headlight.
from microbit import *
import maqueen


headlights = maqueen.MaqueenHeadLights()

headlights.set_headlight(headlight='left', on=1)

Tasks

  1. Write code to turn on the left headlight, then after a sleep of 1 sec, turn it off.

  2. Write code to turn on the right headlight, then after a sleep of 2 secs, turn it off.


4.3. set_headlights

set_headlights(left=1, right=1)
Turn the red headlights on or off.
left is 1 to turn on the headlight or 0 to turn off the headlight. Default is 1.
right is 1 to turn on the headlight or 0 to turn off the headlight. Default is 1.
The code below turns on both headlights.
from microbit import *
import maqueen


headlights = maqueen.MaqueenHeadLights()

headlights.set_headlights(left=1, right=1)

Tasks

  1. Write code to turn on the left headlight while turning off the right headlight.

  2. Write code to turn on both headlights, then after a sleep of 1 sec, turn them both off.