I am using a button box connected via a serial port for running an experiment in Psychopy.
from binascii import hexlify
import serial
import serial.tools.list_ports as port_list
ports = list(port_list.comports()) # search for the devices
#for p in ports: print (p)
ser = serial.Serial('/dev/ttyUSB0', 19200, bytesize=8, parity='N', stopbits=1, timeout=0)
if(ser.isOpen() == False): #open the serial port only if NOT open yet
ser.open()
ser.flush()
In the experiment, I have 4 routines. Suppose that each routine contains a written text, accordingly text_1
, text_2
, text_3
and text_4
. If the participant is, for example, in text_1
and he/she clicks the button, the experiment moves to text_2
.
However, I am facing the following problem. If the participant is in text_1
and presses quickly twice the button the experiment moves to text_3
and not to text_2
as if something is storing the information. I would like instead that if you are in text_1
and you press twice, only the first press is considered.
Each text
code is like that
ser.flush()
for line in ser.read(1):
hex = hexlify(line)
num_1=int(hex, 16)
continueRoutine = False #this makes the experiment go to the next text
What could I add to make it like there is no storing of information (if this is what is really happening)?