Hi Yangfan,
I don’t think that is a very safe method of synchronising a camera with pyControl behavioural data because pyControl does not record the times of the pulses generated by Digital_output.pulse(), so if they did drift relative to the pyControl clock for any reason you would not know about it. To trigger a camera with regularly timed pulses I suggest doing it using a timer as shown below, using the output_event argument to ensure the timer events get written to the data file. That way you have the time of each pulse recorded in the pyControl data file using the same clock as all the other behavioural data.
best,
Thomas
# In hardware definition.
cam_trigger = Digital_output(pin = board.port_1.DIO_A,inverted = True)
# In task file.
def run_start():
# Set timer to trigger first pulse.
set_timer('camera_pulse', 1*ms, output_event=True)
def all_states(event):
if event == 'camera_pulse':
# Turn on camera pulse and set timers to turn off current pulse and trigger the next one.
cam_trigger.on()
set_timer('camera_pulse', 10*ms, output_event=True)
set_timer('camera_pulse_off', 5*ms)
elif event == 'camera_pulse_off':
cam_trigger.off()