Send trigger by serial port after mouse click

Hello everyone, I´m trying to send trigger markers from my stimuli computer (running psychopy) to the acquisition device through a serial port. I already test the port sending triggers at the same time that stimuli presentation, with no trouble. Now, I want to send a trigger marker when the subject react to that stimuli pressing the mouse (just the click). So far I made this simple trial that contains my issue.

In the mouse code section I reset the mouse and in every frame y call the ‘getPressed’, but I’m not sure if that resolve my problem. The code run, but I don’t see the triggers when I click during the test (but I can see perfectly the stim triggers)

Thank you in advance

click_trigger.psyexp (14.6 KB)

So far i Handled to see the triggers with this code in each frame section

click = mouse.getPressed()[0] #check for the left button
if click == 1:
port.write([5]) #write trigger
mouse.clickReset() #clear buffer

In the image the 2s are visual stimuli triggers and the 5s are the clicks (some of them when i keep the button pushed down). I just need the first trigger of the click, no the whole time that is pressed. Any suggestions?

Thank you for your time


.

´´´´
##begin experiment tab
import serial
port = serial.Serial(‘COM3’, baudrate=115200) #depends of your port

##begin routine tab
trigger sent = False # flag variable

##each frame tab
buttons = mres_goE.getPressed()[0] #mres_goE is the name of the mouse object
if buttons == 1 and not trigger_sent:
port.write([3]) #in my case for active view software need the .
trigger_sent = True

##End experiment tab

port.close()
´´´´