From ce858e23f22a411be915c565175c6fcdc2d24de4 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 20 Mar 2021 20:56:58 +0100 Subject: [PATCH] Accelerometer complete --- main.py | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 0c977f0..a5afa68 100644 --- a/main.py +++ b/main.py @@ -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()