I have a very simple experiment that I’ve managed not to make work… The experiment should play a beep sound each time the space button is pressed for duration of 1 second and pressing + should increase volume by 10% and pressing - should decrease volume by 10%. However, my code only play the beep sound only once
Here is example of my code
#Begin experiment import serial from psychopy import sound import serial beep = sound.Sound('test_100_200Hz.wav', name='$beep', secs = 1) volume_level = 0.1 beep.setVolume(volume_level) timer = core.Clock() port_trigger_eeg = serial.Serial('COM5') port_trigger_eeg.write([0x00]) #begin routine beepOnsets= beepISIs= #Each frame if event.getKeys(keyList = ['space']): beep.play() timer = core.Clock() port_trigger_eeg.write([0x01]) elif timer.getTime() > 1 and not event.getKeys(): beep.stop() port_trigger_eeg.write([0x00]) if event.getKeys(keyList = ['+']): beep.setVolume(volume_level+0.1) if event.getKeys(keyList = ['-']): beep.setVolume(volume_level-0.1) #End routine thisExp.addData('beepISIs', beepISIs) thisExp.addData('beepOnsets', beepOnsets)
Any help would be greatly appreciated.