microbit Blinkenlights

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.


# Microbit Blinkenlights
from microbit import *

blink_interval = 500
pixel_intensity = 9

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

    sleep(blink_interval)    

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