Hi! I am trying to code an experiment in psychopy which uses pyserial to send various triggers at the beginning/end of trials. My question is a general one regarding the organisation of code around stimulus timing and when to send triggers & record keypresses. I am using clock-based timing.
I want to send a trigger upon window flipping of my stimulus and have the simulus drawn using clock-based timing. How do I send a trigger at the same time as flipping & at the end of the trial but not upon every loop of my while statement, if that makes sense?
fixation_cross(1) tapping_clock.reset() port.write('K'.encode()) # Start trigger while tapping_clock.getTime() < 10: tapping_text.draw() win.flip() port.write('k'.encode()) # End trigger
I’m having the same issue with the code below where I want to send a start trigger upon presentation of the letter and have the ending trigger at the end of the trial (2 seconds) with keypresses being searched for inbetween.
nback_clock.reset() nback_kb.clock.reset() while nback_clock.getTime() < 2: if nback_clock.getTime() < 0.5: letter_present.draw() else: blank.draw() win.flip() port.write('F'.encode()) # Start trial trigger port.write('f'.encode()) # End trial trigger keys_n = nback_kb.getKeys(keyList = ['left', 'right']) # Get responses if len(keys_n) > 0: if corrAns == keys_n[-1].name: answer = 1 elif corrAns != keys_n[-1].name: answer = 0 elif keys_n in ['', , None]: answer = 'None' else: answer = 'error'
Sorry for all the questions, I have used psychopy before but I am not particularly well-versed in coding in psychopy and how to structure trials in this way. I would appreciate any help or advice as I can code it, I’m just unsure as how to structure it. Thank you!