-
Notifications
You must be signed in to change notification settings - Fork 2
/
OptogeneticStimProtocol.sc~
129 lines (109 loc) · 3.4 KB
/
OptogeneticStimProtocol.sc~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
% PROGRAM NAME: OPTOGENETICSSTIMPROTOCOL
% AUTHOR: MCZ
% DESCRIPTION: Will pulse the laser at a specified pulse frequency and pulse duration for a specified amount of time.
% Inputs mapped: 1 2 3 4 = [0.1Hz, 0.2Hz, 1Hz, 4Hz]
% 5 6 7 = [100ms, 500ms, 1000ms]
% Outputs mapped: 1 = [Laser]
%VARIABLES
int expDuration= 20000 % duration of experiment in ms
int totalDuration= 0 % duration of current stimulation
int stimWidth= 0 % stimulation duration [100ms, 500ms, 1000ms]
int stimFreq= 0 % stimulation frequency [0.1Hz, 0.2Hz, 1Hz, 4Hz]
int isRunning= 0 % function execution lockout
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCTIONS
% -----------------------
% Function Name: Stimulate
% Description: This function activates the laser, using variable stimFreq and StimWidth times
% -----------------------
function 1
% if you want the laser on longer than the on/off time, or these vars don't exist yet do
if stimWidth >= stimFreq || stimWidth== 0 || stimFreq== 0 || isRunning==1 do
if stimWidth==0 || stimFreq== 0 do
disp('Error, stimWidth or StimFreq values are not set')
else if isRunning==1 do
disp('Error, function is already running')
else do
disp('Error, stimWidth is longer than stimFrequency')
end
else do
isRunning=1
% while time elapsed is less than specified duration, do every frequency of stimulation
while totalDuration <= expDuration do every stimFreq
portout[1]= 1 % turn the laser on
do in stimWidth % after pulse duration, turn the laser off
portout[1]= 0
end
totalDuration= totalDuration + stimFreq % add up time elapsed
then do % when stimulation is done, reset totalDuration
disp('done!')
totalDuration= 0
isRunning= 0
end
end
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CALLBACKS -- EVENT-DRIVEN TRIGGERS
% Button #1 - 0.1Hz Stimulation Selected
callback portin[1] up
disp('portin1 up- 0.1Hz Stimulation Selected')
stimFreq= 10000 % every 10sec
trigger(1)
end;
callback portin[1] down
disp('portin1 down')
end;
% Button #2 - 0.2Hz Stimulation Selected
callback portin[2] up
disp('portin2 up- 0.2Hz Stimulation Selected')
stimFreq= 5000 % every 5sec
trigger(1)
end;
callback portin[2] down
disp('portin2 down')
end;
% Button #3 - 1Hz Stimulation Selected
callback portin[3] up
disp('portin3 up- 1Hz Stimulation Selected')
stimFreq= 1000 % every 1sec
trigger(1)
end;
callback portin[3] down
disp('portin3 down')
end;
% Button #4 - 4Hz Stimulation Selected
callback portin[4] up
disp('portin4 up- 4Hz Stimulation Selected')
stimFreq= 250 % every 250msec
trigger(1)
end;
callback portin[4] down
disp('portin4 down')
end;
% DIP #1 - 100ms Stimulation Width Selected
callback portin[5] up
disp('portin5 up- 100ms Stimulation Width Selected')
stimWidth= 100
trigger(1)
end;
callback portin[5] down
disp('portin5 down')
end;
% DIP #2 - 500ms Stimulation Width Selected
callback portin[6] up
disp('portin6 up- 500ms Stimulation Width Selected')
stimWidth= 500
trigger(1)
end;
callback portin[6] down
disp('portin6 down')
end;
% DIP #3 - 1000ms Stimulation Width Selected
callback portin[7] up
disp('portin7 up- 1000ms Stimulation Width Selected')
stimWidth= 1000
trigger(1)
end;
callback portin[7] down
disp('portin7 down')
end;