Ich habe das unten stehende Programm in Python geschrieben und versucht, die Beschleunigungssensor-Ausgabe zu lesen. Wenn ich den Ausgang des Beschleunigungsmessers drucke, bekomme ich 1. Ich rate mir, wie man die tatsächliche Ausgabe in Ziffern erhält, um die genaue Neigung des Beschleunigungsmessers zu kennen.der Ausgang von Beschleunigungssensor adxl335 mit Raspberry Pi verbunden ist 1. Wie man den Ausgang im Dezimalformat
import RPi.GPIO as io # import the GPIO library we just installed but call it "io"
import time
io.setmode(io.BCM)
io.setwarnings(False)
x_axis = 17 # this is the GPIO number our accelerometer's x axis is connected
y_axis = 27 # this is the GPIO number our accelerometer's x axis is connected
z_axis = 22 # this is the GPIO number our accelerometer's x axis is connected
io.setup(x_axis, io.IN) # initialize receiver GPIO to take input
io.setup(y_axis, io.IN) # initialize receiver GPIO to take input
io.setup(z_axis, io.IN) # initialize receiver GPIO to take input
try:
while True:
x = io.input(x_axis)
if x:
print"x-axis ="
print(x)
time.sleep(1)
y = io.input(y_axis)
if y:
print"y-axis"
print(y)
time.sleep(1)
z = io.input(y_axis)
if z:
print"z-axis"
print(z)
time.sleep(1)
except KeyboardInterrupt:
print("Received Interrupt")
output
[email protected] /opt/embedded $ sudo python accelerometer.py
x-axis =
1
y-axis
1
z-axis
1
x-axis =
1
y-axis
1
z-axis
1
x-axis =
1
y-axis
1
z-axis
1