马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 小洛璃 于 2020-5-1 16:30 编辑
为了监听nunchuk发出的信号,并最终将其输出至屏幕上,正常应该是转动手柄方向键,输出数值应随之改变,但结果是个固定值
import smbus
import time
bus = smbus.SMBus(1)
bus.write_byte_data(0x52,0x40,0x00)
time.sleep(0.1)
while True:
try:
bus.write_byte(0x52,0x00)
time.sleep(0.1)
data0 = bus.read_byte(0x52)
data1 = bus.read_byte(0x52)
data2 = bus.read_byte(0x52)
data3 = bus.read_byte(0x52)
data4 = bus.read_byte(0x52)
data5 = bus.read_byte(0x52)
joy_x = data0
joy_y = data1
accel_x =(data2 << 2) + ((data5 & 0x0c) >> 2)输
accel_y =(data3 << 2) + ((data5 & 0x0c) >> 4)
accel_z =(data4 << 2) + ((data5 & 0x0c) >> 6)
buttons = data5 & 0x03
button_c = (buttons == 1)
button_z = (buttons == 2)
print(' Jx: %s Jy: %s Ax: %s Ay: %s Az: %s Bc: %s Bz: %s' % (joy_x,joy_y,accel_x,accel_y,accel_z,button_c,button_z))
except Exception as e:
print(e)
输出结果是Jx:255 Jy: 255 Ax: 1023 Ay: 1023 Az: 1023 Bc: False Bz: False
Jx:255 Jy: 255 Ax: 1023 Ay: 1023 Az: 1023 Bc: False Bz: False
Jx:255 Jy: 255 Ax: 1023 Ay: 1023 Az: 1023 Bc: False Bz: False
无线循环下去,无论手柄怎么动,数值都不变
|