microbit Blinkenlights

A tiny snippet of code often used when the microbit is not showing anything specifically on the screen but you want to indicate that something is happening in the background - like it’s broadcasting on radio.

from microbit import *

poll_interval = 500
intensity = 9

while True:
    display.set_pixel(2, 2, intensity)
    intensity = 0 if intensity == 9 else 9

It turns the centre pixel of the display on and off at a frequency decided by the polling interval.