课程难度
课程任务
制作一个数字画板,通过A/B键的操作,在屏幕上完成数字画的制作。每次按下A按钮,灯向右移动一个像素并亮起,之前位置关闭,不影响按下B按钮亮起的灯,每行结束后,换到下一行的开始,按下B确认,如果亮起则关闭,如果关闭则亮起。
代码
# Imports go at the top
from microbit import *
x=0
y=0
def liangdeng(x, y):
liangdu = display.get_pixel(x, y)
if liangdu == 9:
display.set_pixel(x, y, 0)
else:
display.set_pixel(x, y, 9)
display.set_pixel(x, y, 5)
while True:
if button_a.was_pressed():
if display.get_pixel(x, y) == 5:
display.set_pixel(x, y, 0)
x+=1
if x == 5:
x = 0
y += 1
if y == 5:
x=0
y=0
display.set_pixel(x, y, 5)
if button_b.was_pressed():
liangdeng(x, y)