microbit/main.py

42 lines
879 B
Python
Raw Normal View History

2021-03-20 20:43:56 +01:00
from microbit import *
2021-03-20 20:56:58 +01:00
SENSITIVITY = 250
2021-03-20 20:43:56 +01:00
2021-03-20 20:56:58 +01:00
def main():
while True:
x = accelerometer.get_x()
y = accelerometer.get_y()
2021-03-20 20:43:56 +01:00
2021-03-20 20:56:58 +01:00
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
2021-03-20 20:43:56 +01:00
else:
2021-03-20 20:56:58 +01:00
if y < -SENSITIVITY:
image = Image.ARROW_N
elif y > SENSITIVITY:
image = Image.ARROW_S
else:
image = Image.CLOCK1
return image
2021-03-20 20:43:56 +01:00
2021-03-20 20:56:58 +01:00
if __name__ == "__main__":
main()