Code for very simple state machine

From Bcontrol

The code below focuses on what you need in order to make the state machine diagram of the figure. For complete standalone example code, including commands to initialize sounds, and start running the state machine, etc, go here

%  Elsewhere we define sound #1 to be a 1-sec long white noise

sma = StateMachineAssembler;

sma = add_state(sma, 'name', 'STATE_0', 'self_timer', 0.0001, ...
   'input_to_statechange', {'Tup', 'my_start'});

sma = add_state(sma, 'name', 'MY_START', ...
   'input_to_statechange', {'Cin', 'light_on'});

sma = add_state(sma, 'name', 'LIGHT_ON', 'self_timer', 2, ...
   'input_to_statechange', {'Tup', 'punish' ; 'Cin', 'reward'}, ...
   'output_actions', {'DOut', center1led});

sma = add_state(sma, 'name', 'REWARD', 'self_timer', 0.2, ...
   'output_actions', {'DOut', left1water}, ...
   'input_to_statechange', {'Tup', 'state_0'});

sma = add_state(sma, 'name', 'PUNISH', 'self_timer', 1, ...
   'output_actions', {'SoundOut', 1}, ...
   'input_to_statechange', {'Tup', 'state_0'});

Simplest state machine.jpg