While the classic theory of input/output automata is only aware of events, Harel statecharts and as such CREATE Statecharts have many more features, including variables. Variables allow to use quantitative values in statecharts and are very comparable to variables in programming languages.
To explain the use of variables we extend the light switch by adding dimming functionality. The light switch supports ten different dimming levels. It still defines the states Off and On with mutual transitions which are triggered by switch events.
To handle the dimming functionality the light switch statechart defines two additional elements:
To handle the brightness level correctly the statechart must maintain its value depending on the active state and the occurring events. As such it defines the following rules:
entry / brightness = 0
. This action assigns 0 and is executed whenever state
Off is entered.
This example shows how variables can be used in conjunction with more complex conditions. Variables can be assigned and can also be used in conditions and calculation expressions. Actions can be specified as part of a transition as well as part of states.
The statechart interface is defined as:
interface:
in event switch
in event changeBrightness
var brightness: integer
brightness: