SPLat Logo

Finite State Machines - Make light work of complex functions

SPLat will be shutdown for the Christmas Holiday season from Thursday 20 December 2018 thru Sunday 6 January 2019. We will check emails periodically and will continue to process orders but at a slower pace. Santa hat

Program your own Finite State Machine using a SPLat Controller for only $29.00.

The EC1 "EasyOne", a 32-bit fully featured SPLat Controller with USB and true multi-tasking is a easy way to learn and a cheap way to build your project.

VB.NET - Code overview

Finite State Machine program listing

Figure 11 is a listing of the program that has been collapsed to give an overview of the various subs (in VB.NET subs used more frequently than functions, though the two are very similar)

I have grouped the 9 subs into logical groupings, to help you see the overall pattern.

Global variables

Two variables are declared (DIM'd) at the top of the program..

Event handlers

These are the subs that respond to the various events that can occur during the life and times of the FSM.

Outputs

I have chosen to locate the output simulation code in separate subs. This makes it easier if you want to change how an output is simulated. The two outputs are the heater and the alarm indicator.

State transitions

I have made a single sub that handles all the state transitions. It is called with the destination state number as its argument. It switches the global state number and performs all required actions. HelpTip

Timer management

My particular style of creating timeouts in VB is to use a timer control with a short interval and to count off Timer_Tick events.