Fork me on GitHub
Tutorials / Examples / W3C Microwave

W3C Microwave

Ported from Alex Zhornyak's SCXML tutorial collection.

This ports the W3C microwave oven example from Alex Zhornyak's SCXML tutorial collection into a browser-executable SCION example. The left pane shows the live statechart, and the right pane is an HTML5 microwave panel that sends SCXML events.

0
sec
Power
on
Mode
off
Door
closed
Timer
0 / 5

SCXML source

<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml"
       version="1.0"
       datamodel="ecmascript"
       initial="off">

  <!-- trivial 5 second microwave oven example -->
  <datamodel>
    <data id="cook_time" expr="5"/>
    <data id="door_closed" expr="true"/>
    <data id="timer" expr="0"/>
  </datamodel>

  <state id="off">
    <transition event="turn.on" target="on"/>
  </state>

  <state id="on">
    <initial>
      <transition target="idle"/>
    </initial>

    <transition event="turn.off" target="off"/>
    <transition cond="timer &gt;= cook_time" target="off"/>

    <state id="idle">
      <transition cond="door_closed" target="cooking"/>
      <transition event="door.close" target="cooking">
        <assign location="door_closed" expr="true"/>
      </transition>
    </state>

    <state id="cooking">
      <transition event="door.open" target="idle">
        <assign location="door_closed" expr="false"/>
      </transition>

      <transition event="time">
        <assign location="timer" expr="timer + 1"/>
      </transition>
    </state>
  </state>
</scxml>