Accelerometer complete

This commit is contained in:
Gabriel Augendre 2021-03-20 20:56:58 +01:00
parent 0350902e4c
commit ce858e23f2

46
main.py
View file

@ -1,19 +1,41 @@
from microbit import *
SENSITIVITY = 10
SENSITIVITY = 250
while True:
x = accelerometer.get_x()
y = accelerometer.get_y()
def main():
while True:
x = accelerometer.get_x()
y = accelerometer.get_y()
if x > SENSITIVITY and y > SENSITIVITY:
image = Image.ARROW_NE
elif x > SENSITIVITY and y < -SENSITIVITY:
image = Image.ARROW_SE
elif x > SENSITIVITY:
image = Image.ARROW_E
image = get_image(x, y)
display.show(image)
def get_image(x, y) -> Image:
if x > SENSITIVITY:
if y < -SENSITIVITY:
image = Image.ARROW_NE
elif y > SENSITIVITY:
image = Image.ARROW_SE
else:
image = Image.ARROW_E
elif x < -SENSITIVITY:
if y < -SENSITIVITY:
image = Image.ARROW_NW
elif y > SENSITIVITY:
image = Image.ARROW_SW
else:
image = Image.ARROW_W
else:
image = None
if y < -SENSITIVITY:
image = Image.ARROW_N
elif y > SENSITIVITY:
image = Image.ARROW_S
else:
image = Image.CLOCK1
return image
display.show(image)
if __name__ == "__main__":
main()