Niveau à leds

Description

Concevoir un programme qui permet de transformer la carte en niveau à bulle (c'est à dire qu'elle indique si elle est horizontale ou non).

Résultat attendu

Incliner :

         

Afficher la solution

from microbit import *
horiz = True
while True:
    display.clear()
    if accelerometer.get_y() > 20:
        display.set_pixel(2,4,9)
        horiz = False
    if accelerometer.get_y() < -20:
        display.set_pixel(2,0,9)
        horiz = False
    if accelerometer.get_x() < -20:
        display.set_pixel(0,2,9)
        horiz = False
    if accelerometer.get_x() > 20:
        display.set_pixel(4,2,9)
        horiz = False
    if horiz:
        display.set_pixel(2,2,9)

    sleep(20)