Working with joystick and timing out
I am trying to write a code in an inline_script code that suppose to work with a joystick I have.
I want 'up' response to be stored as 'o', 'down ' response as 'b' and to quit if no response is given after 2 seconds.
That's what I have by now:
t0 = clock.time() joystick.flush() NowPoint = joystick.get_joyaxes(timeout=None) #Collect initial position of the joystick Baseline = NowPoint #Define the Y axis baseline stop = False var.response = 'None' #if no response is taken, so it'll be None anyway while not stop: Current = joystick.get_joyaxes(timeout=None) #Get current position Value = Current #get the Y axis Now = self.time() #What time is it? if Now-t0>2000: #Is it Timeout time? Timeout=Now-t0 print(Timeout) stop=True if Baseline + abs(Value) > 0.1: #Compare position to baseline var.RT = self.time() - t0 #Measure RT if Value <0: var.response = 'o' if Value > 0: var.response = 'b' stop=True
The problem is that the 'Timeout' is highly varied and could reach to up to 2600 msec! that's 600 msec after what I need.
I will be grateful for any tips making the timeout (or the code in general) more accurate.