Created
April 18, 2019 13:18
-
-
Save martinohanlon/324ab89ce4c5275be132536c3eb9480d to your computer and use it in GitHub Desktop.
Sense HAT tilting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sense_hat import SenseHat | |
sense = SenseHat() | |
tilt = "flat" | |
def display_orientation(yaw, pitch, roll, tilt): | |
print("{:06.2f}|{:06.2f}|{:06.2f}|{}".format(yaw, pitch, roll, tilt)) | |
while True: | |
pos = sense.get_orientation() | |
#display_orientation(pos["yaw"], pos["pitch"], pos["roll"], tilt) | |
if pos["roll"] > 270 and pos["roll"] < 345 and tilt != "forward": | |
tilt = "forward" | |
print(tilt) | |
elif pos["roll"] > 15 and pos["roll"] < 90 and tilt != "backward": | |
tilt = "backward" | |
print(tilt) | |
elif pos["pitch"] > 15 and pos["pitch"] < 90 and tilt != "left": | |
tilt = "left" | |
print(tilt) | |
elif pos["pitch"] > 270 and pos["pitch"] < 345 and tilt != "right": | |
tilt = "right" | |
print(tilt) | |
elif (pos["pitch"] >= 345 or pos["pitch"] <= 15) and (pos["roll"] >= 345 or pos["roll"] <= 15) and tilt != "flat": | |
tilt = "flat" | |
print(tilt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment