Implementing Finite State Machine

I have been reading up about Finite State Machines (FSM) as I want to implement one for a project.

I found this thread which in Post#5 has a link to Digital DIY article on implementing FSM.

My project involves reading the state of a brew switch on an espresso machine, controlling the machine’s pump, reading data from a load cell.

The FSM will pulse the pump on for 1 sec, off for 2 sec (repeat this twice), then turn the pump on for 25 sec while reading and printing mass from load cell every 1/2 sec. Once it reaches 25 sec it turns pump off & sounds a buzzer for 2 sec on, 5 sec off to tell user to turn brew switch off. If user doesn’t turn off Brew Switch, it sounds buzzer again until user complies.

So I wrote out my Static (S) & Transitional (T) States following the guidelines from the Digital DIY article as follows:

  1. Wait for Brew Switch to be turned on (S)
  2. Turn pump on, take note of time, tare the load cell (T)
  3. Wait for 1 sec to pass (S)
  4. Turn pump off, take note of time (T)
  5. Wait for 2 sec to pass, increment counter1 (S)
  6. Goto Step 2 if counter1 < 3, otherwise goto step 7 (T)
  7. Turn pump on, take note of time (T)
  8. Wait for 1/2 sec to pass (S)
  9. Print mass and time, increment counter2 (T)
  10. Goto Step 7 if counter2 < 50, otherwise goto Step 11 (T)
  11. Turn off pump, turn on buzzer, take note of time (T)
  12. Wait for 2 sec (S)
  13. Turn buzzer off, take note of time (T)
  14. Wait for 5 sec (S)
  15. Check Brew Switch, if still on, goto Step 11, otherwise goto Step 16.
  16. Goto Step1.

But what if the user just wants to quickly rinse after pulling a shot? I am unsure of how I should be writing the state machine for that case.

Can anyone suggest how to do this?

rosscopicotrain:
But what if the user just wants to quickly rinse after pulling a shot?

I don't understand the terminology but, firstly, how can the program know the user wants a rinse?

11. Turn off pump, turn on buzzer, take note of time (T)
12. Wait for 2 sec (S)
13. Turn buzzer off, take note of time (T)
14. Wait for 5 sec (S)
15. Check Brew Switch, if still on, goto Step 11, otherwise goto Step 16.

The way this is written the buzzer will sound for at least two seconds no matter how fast the Brew switch is turned off.

11. Turn off pump, turn on buzzer, take note of time, Go to State12
12. if Brew Switch is off, turn off buzzer and go to State1
      if two seconds have elapsed, turn off buzzer and go to State13
13. if Brew Switch is off, go to State1
      if five seconds have elapsed, turn on buzzer and go to State12