#获取操作杆轴数
axes = joystick.get_numaxes()
textPrint.tprint(screen, "Number of axes:{}".format(axes))
#获取每个轴的数值
for i in range(axes):
axis = joystick.get_axis(i) #获取每个轴当前的位置 数字表示 取件-1到1之间 0表示居中
textPrint.tprint(screen, "Axis {} value is:{:>6.3f}".format(i, axis))
textPrint.unindent()
#获取手柄按钮数据
buttons = joystick.get_numbuttons()
textPrint.tprint(screen, "Number of buttons:{}".format(buttons))
textPrint.indent()
#获取每个按钮状态
for i in range(buttons):
button = joystick.get_button(i) #获取当前按钮状态 按压True 否False
textPrint.tprint(screen, "button {:>2} value {}".format(i, button))
textPrint.unindent()
#获取方向键状态
hats = joystick.get_numhats() #获取数量
textPrint.tprint(screen, "Number of hats:{}".format(hats))
textPrint.indent()
#获取每个按键的值
for i in range(hats):
hat = joystick.get_hat(i)
textPrint.tprint(screen, "Hat {} value: {}".format(i, str(hat)))
textPrint.unindent()
textPrint.unindent()
#定义多步操作
def walk(step, direction):
if not step:
return ;
if not direction:
direction = 'forward'
run = 0
roundStep = 600 #圈长 大于一圈的长度
for i in range(0, roundStep):
tect = GPIO.event_detected(uPin)
status = GPIO.input(uPin)
#发现事件且处于高电平
if tect == 1 and status == GPIO.HIGH:
run += 1
if direction == 'backward':
motor.oneStepBack(0.003)
elif direction == 'forward':
motor.oneStep(0.003)
#检测停止条件
if run >= step:
motor.stopMoving()
break
time.sleep(0.005) ##每步间的间隔
#print("第%d步" % i)
return run