% Jon Newman
% Multi-parameter activity assay for cultures transfected with
% optical exciters and silencers

% File name
fam = 'tommy';
mea = '20709';
no = '01';

fid = ['paired-pulse_' datestr(now,29) '_hoss-r3_' fam '_' mea '_' no];

N = 10;
u = rand(N,1);
channels = round(rand(size(u)));

% Experiment parameters
t_pre = 20; % seconds
t_dead = 0; % seconds
interpair_time = 10; %seconds
aoff = -0.5;

% pulse parameters
blue_pw = 5; %msec
yellow_pw = 500; %msec
intrapulse_time = 100; %msec


%% Make the protocol

% Storage vectors
T = [0;0];
A = [aoff;aoff];
C = [0;1];
T_D = [0;0];
S_D = [0;0];

% digital bits - all we need to encode is u because everything is
% dependent on that
b_trig = '0'; % one trigger bit
b_chan = '00'; % two bits for the A0 being used
% start time at the end of the pre recording
tot = t_pre;

for i = 1:N

    % First turn blue light on
    T = [T; [tot;tot + blue_pw/1000]];
    C = [C; [0;0]];
    A = [A; [5;aoff]];
    T_D = [T_D; [tot;tot + blue_pw/1000]];
    S_D = [S_D; [3;2]];

    
    % After intra pulse time turn yellow light on
    T = [T; [tot + intrapulse_time/1000;tot + intrapulse_time/1000 + yellow_pw/1000]];
    C = [C; [1;1]];
    A = [A; [5;aoff]];
    T_D = [T_D; [tot + intrapulse_time/1000;tot + intrapulse_time/1000 + yellow_pw/1000]];
    S_D = [S_D; [5;4]];
    tot = tot + interpair_time;
     
end

T = [T;tot;tot];
A = [A;aoff;aoff];
C = [C;1;0];

% Write the .oldig file
close all
stairs(T,A)
makeauxfile(fid,T,C,A);
makedigfile(fid,T_D,S_D);
