Hi Kate,
On the wiki there's a section documenting the serial interfaces of the state machine and its modules, including WavePlayer.
The serial interface's 'State Machine' section explains which bytes to send from the state machine to the WavePlayer module to trigger, stop playback, etc.
Here's how you'd do what you're describing:
In your protocol (MATLAB), before your main loop:
%% Create waveplayer object
if (isfield(BpodSystem.ModuleUSB, 'WavePlayer1'))
W = BpodSystem.ModuleUSB.WavePlayer1;
else
error('Error: To run this protocol, you must first pair the WavePlayer1 module with its USB port on the Bpod console.')
end
%% Set up waveplayer
W.SamplingRate = 1000;
W.loadWaveform(1, 5); % Loads a single 5V sample as waveform#1
In your protocol (MATLAB), in the state where you want to trigger the waveform:
'OutputActions', {'WavePlayer1', ['P' 3 0]} % Play waveform#1 on channels 1 and 2.
Here,
'P' is the serial interface byte code for playback.
3 in binary is '11', indicating to play on channels 1 and 2.
0 is waveform#1 (using zero-indexing since it's an Arduino board)
Since you're sampling at 1kHz, a single sample will play 5V on channels 1+2 for 1ms.
FYI, the analog output module isn't really necessary to send out TTL pulses - BNC output channels 1+2 on the state machine are a simpler option - and they're galvanically isolated, reducing noise and the potential for ground loops on your rig. To set BNC output Ch1+2 high for the duration of a state, use:
'OutputActions', {'BNC1', 1, 'BNC2', 1} % Set BNC output channels 1 and 2 to high (5V).
If you need to run a more complicated sync waveform on those channels in parallel with the flow of states, consider linking them to a looping global timer as in this example: (https://github.com/sanworks/Bpod_Gen2/blob/master/Examples/State%20Machines/Global%20Timers/GlobalTimerExample_DigitalLoop_NoEvents.m).
I hope this helps,
-Josh