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 * from microbit import *
SENSITIVITY = 10 SENSITIVITY = 250
while True: def main():
x = accelerometer.get_x() while True:
y = accelerometer.get_y() x = accelerometer.get_x()
y = accelerometer.get_y()
if x > SENSITIVITY and y > SENSITIVITY: image = get_image(x, y)
image = Image.ARROW_NE display.show(image)
elif x > SENSITIVITY and y < -SENSITIVITY:
image = Image.ARROW_SE
elif x > SENSITIVITY: def get_image(x, y) -> Image:
image = Image.ARROW_E 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: 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()