Accelerometer complete
This commit is contained in:
parent
0350902e4c
commit
ce858e23f2
1 changed files with 34 additions and 12 deletions
42
main.py
42
main.py
|
@ -1,19 +1,41 @@
|
||||||
from microbit import *
|
from microbit import *
|
||||||
|
|
||||||
SENSITIVITY = 10
|
SENSITIVITY = 250
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
while True:
|
while True:
|
||||||
x = accelerometer.get_x()
|
x = accelerometer.get_x()
|
||||||
y = accelerometer.get_y()
|
y = accelerometer.get_y()
|
||||||
|
|
||||||
if x > SENSITIVITY and y > SENSITIVITY:
|
image = get_image(x, y)
|
||||||
image = Image.ARROW_NE
|
|
||||||
elif x > SENSITIVITY and y < -SENSITIVITY:
|
|
||||||
image = Image.ARROW_SE
|
|
||||||
elif x > SENSITIVITY:
|
|
||||||
image = Image.ARROW_E
|
|
||||||
else:
|
|
||||||
image = None
|
|
||||||
|
|
||||||
display.show(image)
|
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:
|
||||||
|
if y < -SENSITIVITY:
|
||||||
|
image = Image.ARROW_N
|
||||||
|
elif y > SENSITIVITY:
|
||||||
|
image = Image.ARROW_S
|
||||||
|
else:
|
||||||
|
image = Image.CLOCK1
|
||||||
|
return image
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in a new issue