1. LED Code Ordering
1.1. Question 1
Put the lines in order to build an ongoing blinker loop that switches an LED on Pin 2 fully ON and OFF every half-second.
Drag and drop lines into the correct order and click to adjust indentation:
☰
☰
sleep(500)
☰
pin2.write_digital(1)
☰
from microbit import *
☰
while True:
☰
pin2.write_digital(0)
☰
sleep(500)
1.2. Question 2
A student connects a physical indicator light to Pin 1.
Arrange the code lines to create a loop that checks Button B. If Button B is actively down, turn the indicator light fully ON. Otherwise, turn it fully OFF.
Drag and drop lines into the correct order and click to adjust indentation:
☰
else:
☰
if button_b.is_pressed():
☰
pin1.write_digital(0)
☰
pin1.write_digital(1)
☰
from microbit import *
☰
☰
while True:
1.3. Question 3
A student wants to flash a connected digital LED on Pin 0 a specific number of times.
Arrange the lines to run a loop that pulses the LED ON for a duration that is a multiple of 300 milliseconds, based on a sequence of numbers. After each pulse, the LED should be turned OFF for 300 milliseconds.
Drag and drop lines into the correct order and click to adjust indentation:
☰
from microbit import *
☰
pin0.write_digital(1)
☰
for count in pulse_sequence:
☰
sleep(300)
☰
pulse_sequence = [1, 2, 3]
☰
pin0.write_digital(0)
☰
☰
sleep(300 * count)
1.4. Question 4
Rearrange the lines to create an alternating toggle system on Pin 0 and Pin 1.
The loop should run four times, toggling the two pins between ON and OFF every 400 milliseconds.
The first toggle should be Pin 0 ON, Pin 1 OFF, the second toggle should be Pin 0 OFF, Pin 1 ON, the third toggle should be Pin 0 ON, Pin 1 OFF, and the fourth toggle should be Pin 0 OFF, Pin 1 ON.
steps % 2 == 0 means that the step is even, and steps % 2 == 1 means that the step is odd.
Drag and drop lines into the correct order and click to adjust indentation:
☰
pin0.write_digital(0)
☰
sleep(400)
☰
for steps in range(4):
☰
if steps % 2 == 0:
☰
from microbit import *
☰
pin0.write_digital(1)
☰
else:
☰
☰
pin1.write_digital(0)
☰
pin1.write_digital(1)
1.5. Question 5
Put the code snippets in order so that when Button A is actively pressed down, it should write a half-brightness analog signal (512) to an LED on Pin 2. Otherwise, full brightness (1023) should be written to the LED. The loop should run every 250 milliseconds.
Drag and drop lines into the correct order and click to adjust indentation:
☰
sleep(250)
☰
while True:
☰
☰
from microbit import *
☰
pin2.write_analog(512)
☰
if button_a.is_pressed():
☰
pin2.write_analog(1023)
☰
else:
1.6. Question 6
Arrange the lines to loop through a sequence tuple of brightness values to steadily increase the intensity of an LED on Pin 0.
Drag and drop lines into the correct order and click to adjust indentation:
☰
☰
from microbit import *
☰
for value in levels:
☰
sleep(200)
☰
levels = [0, 256, 512, 768, 1023]
☰
pin0.write_analog(value)
☰
while True:
1.7. Question 7
Arrange the code segments to create a multi-LED delayed wave sequence.
As the loop index increases, Pin 0 updates instantly, while Pin 1 safely reads a delayed step behind by validating that the item index has reached 1 or higher.
Drag and drop lines into the correct order and click to adjust indentation:
☰
from microbit import *
☰
pin0.write_analog(brightness_list[i])
☰
for i in range(4):
☰
brightness_list = [0, 512, 1023, 1023]
☰
sleep(250)
☰
☰
pin1.write_analog(brightness_list[i - 1])
☰
while True:
☰
if i >= 1: