SetGlobalTimer

SetGlobalTimer()

Description

Sets the duration of a global timer.

  • Unlike state timers, global timers can be triggered from any state (as an output action), and handled from any state (by causing a state change).

  • Significantly more sophisticated global timers are available in the 'beta' repository branch.

  • For more on Global Timers, see Using State Matrices.

Syntax

NewStateMatrix = SetGlobalTimer(StateMachineStruct, TimerNumber, TimerDuration)

Parameters

  • StateMachineStruct: The state machine description whose global timer you are setting (typically named 'sma').

  • TimerNumber: The number of the timer you are setting (an integer, 1-5).

  • TimerDuration: The duration of the timer, following timer start (0-3600 seconds)

Returns

  • A state machine struct, updated with the new global timer settings.

Example

This code generates a state machine that sets a global timer for 3.5 seconds, triggers it in the first state, and handles it in the second and third states.

sma = NewStateMatrix();

sma = SetGlobalTimer(sma, 1, 3.5);

sma = AddState(sma, 'Name', 'State1', ...

'Timer', 0,...

'StateChangeConditions', {'Tup', 'State2'},...

'OutputActions', {'GlobalTimerTrig', 1});

sma = AddState(sma, 'Name', 'State2', ...

'Timer', 0,...

'StateChangeConditions', {'Port1In', 'State3', 'GlobalTimer1_End', 'exit'},...

'OutputActions', {});

sma = AddState(sma, 'Name', 'State3', ...

'Timer', 0,...

'StateChangeConditions', {'Port1Out', 'State2', 'GlobalTimer1_End', 'exit'},...

'OutputActions', {});