Exercise 1 – Basic features

By doing this exercise you will get familiar with the basic features of the statechart editor and the simulator.

You will create a statechart for a simple light controller. In the first step it is nothing else than a plain switch. You can disregard everything (even the bulb) except for the button that provides the input events. The behavior for the switch functionality is very simple:

Creating a statechart model for the light switch

The statechart

Adding states and transitions to the light control

To define this behavior described above you should:

  1. Rename StateA to Off.
  2. Add a new state with name On to the statechart.
  3. Connect both states with transitions. One transition from Off to On and another transition in the opposite direction.

When you are ready, then the model should look like this:

The statechart with two states and transitions.

You'll notice two warning signs.

The editor gives a hint that no trigger is specified for the transition. You will have to add events as the next step …

Adding events

To define and use events you will modify the definition section, i.e. the textual part of the model.

  1. Double-click into the definition section on the left side. A text editor will open.
  2. Place the caret below the comment and define an incoming event with the name button_down. Hint: use [Ctrl]+[Space] to get proposals.
  3. Now you have to specify that the transition should be taken if the button_down event occurs. Select a transition and start typing the event name button_down. As soon as the text editor opens you can once again use [Ctrl]+[Space] to see proposals and complete the input.

When you are done, the model should look like this:

The statechart with event definitions.

There shouldn't be any warning or error markers.

Simulating the statechart

Now it is time to check the light control statechart using the simulator.

  1. Right-click on the statechart model file in the project explorer on the left.
  2. Choose Run As → Statechart Simulation from the context menu.
  3. The Off state should get a red background colour.
  4. Use the simulation view to raise the button_down event.

You will be able to switch between both states, and you have used the basic and most commonly used features of the editor and the simulator.

The statechart simulation.