Пример #1
0
def main():
    brick.sound.beep()
    joystickEvent = detectJoystick(['Controller'])
    if joystickEvent:
        robot = Robot(Motor(Port.D), Motor(Port.A), Motor(Port.B), 55, 200)
        t = threading.Thread(target=autoStopLoop, args=(robot, ))
        t.start()

        def onButtonPressed(code):
            if code == BUTTON_X:
                robot.inactive()
                return False
            if code == BUTTON_A:
                robot.fire()
            return True

        def onLeftJoyChanged(x, y):
            robot.drive(x, y)

        def onRightJoyChanged(x, y):
            robot.target(x)

        joystick = JoyStick(joystickEvent)
        joystick.setButtonHandler(onButtonPressed)
        joystick.setJoyLeftHandler(onLeftJoyChanged)
        joystick.setJoyRightHandler(onRightJoyChanged)
        joystick.startLoop()
    else:
        brick.sound.beep()