-
Notifications
You must be signed in to change notification settings - Fork 35
/
GlobalTimerExample_Serial.m
30 lines (29 loc) · 1.54 KB
/
GlobalTimerExample_Serial.m
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
% Example state matrix: A global timer ends an infinite loop. It is
% triggered in the first state, but begins measuring its 3-second Duration
% after a 1.5s onset delay. When the timer begins measuring, it sends byte 2
% to EchoModule1. When the timer's 3 second duration elapses,
% byte 5 is sent to EchoModule1, and a GlobalTimer1_End event occurs
% (handled in both cases by exiting the state machine).
% Requires: behavior ports or lickometers with visible LEDs connected to Ch1 and Ch2
% Requires: an Arduino connected to the Bpod State Machine via the Bpod
% shield, and programmed with EchoModule example firmware:
% https://github.com/sanworks/Bpod_Gen2/tree/master/Examples/Firmware/Bpod%20Shield/EchoModule
sma = NewStateMatrix();
sma = SetGlobalTimer(sma, 'TimerID', 1, 'Duration', 3, 'OnsetDelay', 1.5, 'Channel', 'EchoModule1',...
'OnMessage', 2, 'OffMessage', 5);
sma = AddState(sma, 'Name', 'TimerTrig', ...
'Timer', 0,...
'StateChangeConditions', {'Tup', 'Port1Lit'},...
'OutputActions', {'GlobalTimerTrig', 1});
sma = AddState(sma, 'Name', 'Port1Lit', ...
'Timer', .25,...
'StateChangeConditions', {'Tup', 'Port2Lit', 'GlobalTimer1_End', 'LastState'},...
'OutputActions', {'PWM1', 255});
sma = AddState(sma, 'Name', 'Port2Lit', ...
'Timer', .25,...
'StateChangeConditions', {'Tup', 'Port1Lit', 'GlobalTimer1_End', 'LastState'},...
'OutputActions', {'PWM2', 255});
sma = AddState(sma, 'Name', 'LastState', ...
'Timer', 0.5,...
'StateChangeConditions', {'Tup', '>exit'},...
'OutputActions', {'PWM2', 255});