オンボード LED を操作する / 個々の LED を操作する display.set_pixel()

参考: Programming the BBC Micro:bit: Getting Started With MicroPython, pp.85-86
 
個々の LED を操作するときは display.set_pixel(x 座標, y 座標, 明るさ) という構文で指定する。座標は左上を (0, 0) とする。明るさは 0 ~ 9 で指定する。

from microbit import *

x = 0
y = 0
bright = 9
while True:
    display.set_pixel(x, y, bright)
    sleep(200)
    x += 1
    y += 1
    bright -= 2
    if x > 4:
        x = 0
        y = 0
        bright = 9
        display.clear()
        sleep(200)