from microbit import * def dim_display(): for x in range(0, 5): for y in range(0, 5): c = display.get_pixel(x, y) if c > 1: display.set_pixel(x, y, c - 1) def set_brightness(b): for x in range(0, 5): for y in range(0, 5): if display.get_pixel(x, y) > 0: display.set_pixel(x, y, b) def brighten_display(): for x in range(0, 5): for y in range(0, 5): c = display.get_pixel(x, y) if c > 0 and c < 9: display.set_pixel(x, y, c + 1) def pulse(): d = 80 for x in range(3): brighten_display() sleep(d) d -= 10 for x in range(3): dim_display() sleep(d) d += 10 d = 80 for x in range(7): brighten_display() sleep(d) d -= 10 sleep(200) d = 40 for x in range(7): dim_display() sleep(d) d += 5 sleep(100) display.show(Image.HEART) set_brightness(2) while True: pulse()
Comments