I am trying to create an experiment where particiapnts are shown a baseline and then have a 10s task block. During this task block, I want them to tap their finger at 50bpm for 10s. To do this, I want a metronome sound (a tick sound which will be repeated at 50bpm) so that they can tap their finger to the rhyhtm.
Whilst having triggers which mark the beginning of the entire task block, I also want triggers to be sent at each tick sound so that I can align their neuroimaging data (which is being concurrently recorded) with the tapping. I have the code below so far but I’m not quite sure how to work the looping over 10 seconds with the bpm and would appreciate any help in donig so! I would also appreciate any suggestions as to simplifications as I am aware that it is a big block of code which may impact the accuracy of expeirmental timings. Thank you!
frequency = 50 self.__baseline(10) trigger_sent = False self.__clock.reset() next_flip = self.__win.getFutureFlipTime(clock='ptb') now = ptb.GetSecs() while self.__clock.getTime() < duration: motor_stim.draw() if not trigger_sent: self.__win.callOnFlip(self.__port.write, trigger.encode()) trigger_sent = True if ptb.getSecs() = now + (60/frequency): metronome.play(when=next_flip) now = ptb.GetSecs() self.__win.flip() self.__port.write(end_trigger.encode())