Trying to stop a light blinking "while" loop by querying the position of a gamepad joystick. Can't seem to continuously query while in the loop and break out of the inner loop. Can you suggest fix? Code so far is:

        elif int(controller_input['ABS_Y']) > 140:
            while int(controller_input['ABS_Y']) > 140:

The gamepad_update code reads: def gamepad_update(): # Code execution stops at the following line until gamepad event occurs. events = get_gamepad() return_code = 'No Match' for event in events: event_test = controller_input.get(event.code, 'No Match') if event_test != 'No Match': controller_input[event.code] = event.state return_code = event.code else: return_code = 'No Match'

    return return_code
  • Not Pi specific. A Python tutorial is a good place to start. – joan Nov 7 '20 at 18:15
  • you just need to do something inside the while loop to update controller_input['ABS_Y']. if it sits at the old value, it stays > 140 – Abel Nov 7 '20 at 18:19
  • I have tried adding the "control_code = gamepad_update()" and update the js input to no avail. Position that on top of the while loop and under the while loop and then an "if" statement to query, but no help. – RoboNovice Nov 7 '20 at 19:16
  • Why did you leave out the code that you mentioned in your comment? – jsotola Nov 7 '20 at 19:49
  • Look up what break/continue/pass statements do in python... – Sim Son Nov 8 '20 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.