Exercise 2 – Variables

State machines do not only react on input events by e.g. changing states, but can also perform actions while doing so. One way of performing actions is to manipulate variables.

In this exercise, you will extend the simple light controller. The expected behavior is very simple:

Start with the statechart model included in this project:

The statechart

Defining variables and constants

  1. Add a variable for the power value.
  2. You may define constants for the values 0 and 100, e.g. ON and OFF.

What happens when you simulate the statechart?

Adding actions

Make sure that the power has the right value (see above) in On and Off states. Use actions in states or in transitions or both. Try different variants. Validate the behavior using the simulation.

The statechart with two states and transitions.