from sense_hat import SenseHat sense = SenseHat() orientation = sense.get_orientation_degrees() print("Pitch: {pitch}, Roll: {roll}, Yaw: {yaw}".format(**orientation)) sense.show_message("Pitch: {pitch}, Roll: {roll}, Yaw: {yaw}".format(**orientation))
from sense_hat import SenseHat sense = SenseHat() orientation = sense.get_orientation_degrees() if orientation["pitch"] > 180: print("Sense HAT is upside down!") else: print("Sense HAT is not upside down.")This code will check the pitch value of the Sense HAT and determine if it is upside down or not. The package library used in this example is sense_hat.