A short overview of how the standard sketch is made, could make the reading of this document easier. Functions will be explained later on, which will also clarify more of the functionality.   

  • For short, this is how the standard sketch is setup:
    When the sketch is started –the setup part- it will perform a check on the way the mapping of the I/O is declared. When the check is passed successfully, all I/O is initialized. Every I/O and sensors have a specific record for keeping information like current state or value, a time stamp and the tagname of the I/O or sensor. This information is used for controlling/programming the Finite state machine. 

  • When a second Arduino is connected via I2C, the initialization of the connection is made here. When a supervisory control system is connected via a serial connection, the initialization is made here.

  • Because the use of standard delay() is not preferable, there are some other timer functions available which use a pointer structure. The structure needed for the timers is also created in the setup part.

  • Finally, when interrupt service routines are used, the initialization must be made in the setup.

  • After setup, the infinite main loop is started.

  • The initial state to start is the “START” state.

  • The inputs of all types of I/O are read, filling the earlier mentioned records.

  • Then the Finite state machine main loop is executed. The code of the current state is processed and when there is a transition, the new state(s) for the next run is set.

  • At the end of the main loop of the Finite state machine, all outputs are set as a result from the actions in the state.

  • To process commands given via the standard serial monitor or a supervisor program, a check is done on available input. When there is input, it will be processed here.

  • ....and then back into the infinite main loop(cursive)