%% Set up
% connect the LED to a separate power source so it is always on
PulsePal() % initiate PulsePal
load('/PulsePal/MATLAB/Programs/ParameterMatrix_Example.mat')
ProgramPulsePal(ParameterMatrix); % Sends the default parameter matrix to Pulse Pal

%use with 25.4 V external on low, low on the amplifier
%%
%Connect speaker to Output channel 1
%

sampling_frequency = 0.0001 %10kHz sampling frequency
frequency = 1000;    % Hz
amplitude = 0.25;      % Peak Voltage   
x = 0:.0001:.0029; 	 % start at 0, stop at 3 ms
sinusoid_voltage = amplitude * sin((2*pi*frequency)* x);

SendCustomWaveform(1, sampling_frequency, sinusoid_voltage) % save as custome waveform 1
ProgramPulsePalParam(1, 'CustomTrainID', 1); % Sets output channel 4 to use custom train ID 1
ProgramPulsePalParam(1,'PulseTrainDelay', 0)

%%

%Connect camera to Output channel 2
voltage_camera = [2.8]
pulsetime_camera= [0]
SendCustomPulseTrain(2, pulsetime_camera, voltage_camera)
ProgramPulsePalParam(2, 'CustomTrainID', 2); % Sets output channel 1 to use custom train ID 1
ProgramPulsePalParam(2,'PulseTrainDelay', 0)


%% Code to execute responses 
sampling_frequency = 0.0001 %10kHz sampling frequency
frequency = 1000;    % Hz
amplitude = 0.25;      % Peak Voltage   
x = 0:.0001:.0029; 	 % start at 0, stop at 3 ms
sinusoid_voltage = amplitude * sin((2*pi*frequency)* x);

SendCustomWaveform(1, sampling_frequency, sinusoid_voltage) % save as custome waveform 1
ProgramPulsePalParam(1, 'CustomTrainID', 1); % Sets output channel 4 to use custom train ID 1
ProgramPulsePalParam(1,'PulseTrainDelay', 0)

%camera is triggered during each stimulus

for i= 1:7
    i
    TriggerPulsePal('0011')
    if i < 7
        pause(20); % waits 20 seconds before next A/V stimulus
    end
end
disp('Done with trial')
