from sense_hat import SenseHat sense = SenseHat() while True: gyro = sense.get_gyroscope() print("Gyroscope - X: {x}, Y: {y}, Z: {z}".format(x=gyro['x'], y=gyro['y'], z=gyro['z']))
import matplotlib.pyplot as plt from sense_hat import SenseHat sense = SenseHat() # Start a new figure fig = plt.figure() # Create subplots for each axis x_axis = fig.add_subplot(311) y_axis = fig.add_subplot(312) z_axis = fig.add_subplot(313) # Start an infinite loop to plot data while True: gyro = sense.get_gyroscope() # Get the current time current_time = plt.datetime.datetime.now() # Add new data to each axis plot x_axis.plot(current_time, gyro['x'], 'ro') y_axis.plot(current_time, gyro['y'], 'go') z_axis.plot(current_time, gyro['z'], 'bo') # Pause the loop for a short time plt.pause(0.01)This code will continuously plot the current gyroscope readings on the x, y, and z axis using the matplotlib library. Package library: sense-hat.