Candidate Site Submission

Enter Candidate Site Entries Here

Remember to write the author(s) name for each entry by entering four tildes at the end of your article(~).


Example Entry 1 Title

Example Entry 1 Body

Signature: Rescalante 14:00, 4 March 2009 (MST)


Finite State Machines

A finite state machine (FSM) or simply a state machine, is a model of behavior composed of a finite number of states, transitions between those states, and actions. A finite state machine is an abstract model and can be implemented in both software and hardware.

Vending Machine Example

You have a vending machine to implement using a finite state machine in software. Your vending machine only takes quarters and items cost a dollar. If you receive more than $1 then they were being generous.

http://i719.photobucket.com/albums/ww198/oscarsveliz/public/quarter_state.jpg

0 is initial state On Quarter event transition to next event. On Coin Return event transition to initial state and return change. On Vend event transition to initial state and vend selected item.

Pseudocode

 
nextState(event)
switch state
case 0: if(event == Q) state = 25 else returnCoins break
case 25: if(event == Q) state = 50 else returnCoins and state = 0 break
case 50: if(event == Q) state = 75 else returnCoins and state = 0 break
case 75: if(event == Q) state = 100 else returnCoins and state = 0 break
case 100: if (event == CR) state = 0 and returnCoins else if (event == Q) state = state else vend break
case default: state = state;

Signature: Oscar Veliz 10:23, 24 April 2009 (MST)