def JitteredPulses(self, code=1, width=0.010, port=0, pause_between=3.0, jitter_between=3.0, sync_style="parallel"): """Send pulses separated by a jittered wait. The typical use case for this subroutine is to send a random train of pulses during an EEG experiment to allow for subsequent synchronization of the EEG data with the behavioral data. This would be accomplished by calling JitteredPulses within a Meanwhile as the next state following the instantiation of the Experiment: exp = Experiment() with Meanwhile(): JitteredPulses() """ # loop indefinitely with Loop(): # send a pulse pulse = Pulse(code=code, port=port, width=width, sync_style=sync_style) Done(pulse) # do a jittered wait Wait(duration=pause_between, jitter=jitter_between) # Log the pulse to a pulse-specific log Log(name='pulse', pulse_on=pulse.pulse_on, pulse_code=pulse.code, pulse_off=pulse.pulse_off, pulse_port=pulse.port, pulse_width=pulse.width)
exp = Experiment() with Meanwhile(): KeyRecord(name="record_all_key_presses") Debug(name='Press T+G+D or SHIFT+Q+R') Wait(until=((Key("T") & Key("G") & Key("D")) | (Key("SHIFT") & Key("Q") & Key("R")))) Debug(name='Key Press Test') exp.last_pressed = '' with Loop(conditional=(exp.last_pressed != 'K')): kp = KeyPress(keys=['J', 'K'], correct_resp='K') Debug(pressed=kp.pressed, rt=kp.rt, correct=kp.correct) exp.last_pressed = kp.pressed Log(pressed=kp.pressed, rt=kp.rt) KeyRecord() with UntilDone(): kp = KeyPress(keys=['J', 'K'], correct_resp='K') Debug(pressed=kp.pressed, rt=kp.rt, correct=kp.correct) Wait(1.0) kp = KeyPress() Debug(pressed=kp.pressed, rt=kp.rt, correct=kp.correct) Wait(1.0) kp = KeyPress(duration=2.0) Debug(pressed=kp.pressed, rt=kp.rt, correct=kp.correct) Wait(1.0)
pulse_off=pulse.pulse_off, pulse_port=pulse.port, pulse_width=pulse.width) if __name__ == '__main__': from experiment import Experiment from state import Meanwhile, Debug # set up default experiment exp = Experiment() # test running pulses whilst the rest of the experiment is going with Meanwhile(): with Loop(): pulse = Pulse(code='S1') Wait(duration=1.0, jitter=1.0) Log(name='pulse', pulse_on=pulse.pulse_on, pulse_code=pulse.code, pulse_off=pulse.pulse_off) # First wait for a bit and send some pulses Wait(10) # print something Debug(width=exp.screen.width, height=exp.screen.height) # run the exp exp.run(trace=False)