python3写用i2c连接wii nunchuk手柄至树莓派程序,结果不对,求教是不是程序写错了
本帖最后由 小洛璃 于 2020-5-1 16:30 编辑为了监听nunchuk发出的信号,并最终将其输出至屏幕上{:10_266:}{:10_266:}{:10_266:},正常应该是转动手柄方向键,输出数值应随之改变,但结果是个固定值
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: FalseBz: False
Jx:255 Jy: 255 Ax: 1023 Ay: 1023 Az: 1023 Bc: FalseBz: False
Jx:255 Jy: 255 Ax: 1023 Ay: 1023 Az: 1023 Bc: FalseBz: False
无线循环下去,无论手柄怎么动,数值都不变
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))
输出的是这个,没错吧?
建议在
while True: 循环里面价格延时处理下? xiangjianshinan 发表于 2020-5-2 00:51
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,but ...
对啊,大佬怎么加个延时啊啊 小洛璃 发表于 2020-5-6 21:59
对啊,大佬怎么加个延时啊啊
time.sleep(second) {:7_144:}
页:
[1]