Skip to content

Instantly share code, notes, and snippets.

@martinohanlon
Created April 18, 2019 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinohanlon/324ab89ce4c5275be132536c3eb9480d to your computer and use it in GitHub Desktop.
Save martinohanlon/324ab89ce4c5275be132536c3eb9480d to your computer and use it in GitHub Desktop.
Sense HAT tilting
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