{
  "program": "Motor Control with Interlock",
  "description": "Forward/reverse motor control with start/stop and interlock using OTL/OTU and branching",
  "scan_time_ms": 100,
  "networks": [
    {
      "number": 0,
      "description": "Forward motor — start latch with hold contact",
      "input_branches": [
        {
          "description": "Branch 1: Forward start button",
          "elements": [
            { "type": "NO", "tag": "I0" }
          ]
        },
        {
          "description": "Branch 2: Forward hold contact (parallel)",
          "elements": [
            { "type": "NO", "tag": "M0" }
          ]
        }
      ],
      "output_branches": [
        {
          "description": "Latch forward memory",
          "elements": [
            { "type": "OTL", "tag": "M0" }
          ]
        },
        {
          "description": "Forward motor output",
          "elements": [
            { "type": "OTE", "tag": "Q0" }
          ]
        }
      ]
    },
    {
      "number": 1,
      "description": "Reverse motor — start latch with hold contact",
      "input_branches": [
        {
          "description": "Branch 1: Reverse start button",
          "elements": [
            { "type": "NO", "tag": "I2" }
          ]
        },
        {
          "description": "Branch 2: Reverse hold contact (parallel)",
          "elements": [
            { "type": "NO", "tag": "M1" }
          ]
        }
      ],
      "output_branches": [
        {
          "description": "Latch reverse memory",
          "elements": [
            { "type": "OTL", "tag": "M1" }
          ]
        },
        {
          "description": "Reverse motor output",
          "elements": [
            { "type": "OTE", "tag": "Q1" }
          ]
        }
      ]
    },
    {
      "number": 2,
      "description": "Stop button — unlatch both motors",
      "input_branches": [
        {
          "description": "Stop button",
          "elements": [
            { "type": "NO", "tag": "I1" }
          ]
        }
      ],
      "output_branches": [
        {
          "description": "Unlatch forward",
          "elements": [
            { "type": "OTU", "tag": "M0" }
          ]
        },
        {
          "description": "Unlatch reverse",
          "elements": [
            { "type": "OTU", "tag": "M1" }
          ]
        }
      ]
    },
    {
      "number": 3,
      "description": "Forward run timer — TON with status bits",
      "input_branches": [
        {
          "description": "Forward motor running",
          "elements": [
            { "type": "NO", "tag": "Q0" }
          ]
        }
      ],
      "output_branches": [
        {
          "description": "TON 5000ms (5 second run time)",
          "elements": [
            { "type": "TON", "tag": "T0", "value": 5000 }
          ]
        }
      ]
    },
    {
      "number": 4,
      "description": "Alarm when forward runs > 5 seconds (T0.DN → Q2)",
      "input_branches": [
        {
          "description": "TON done bit",
          "elements": [
            { "type": "TON_DN", "tag": "T0" }
          ]
        }
      ],
      "output_branches": [
        {
          "description": "Alarm output",
          "elements": [
            { "type": "OTE", "tag": "Q2" }
          ]
        }
      ]
    }
  ],
  "io_map": {
    "inputs": [
      { "tag": "I0", "gpio": 27, "description": "Forward start button" },
      { "tag": "I1", "gpio": 26, "description": "Stop button" },
      { "tag": "I2", "gpio": 33, "description": "Reverse start button" }
    ],
    "outputs": [
      { "tag": "Q0", "gpio": 25, "description": "Forward motor relay" },
      { "tag": "Q1", "gpio": 32, "description": "Reverse motor relay" },
      { "tag": "Q2", "gpio": 4,  "description": "Overrun alarm" }
    ]
  },
  "timers": [
    { "tag": "T0", "type": "TON", "preset_ms": 5000, "description": "Forward run time monitor" }
  ],
  "memory": [
    { "tag": "M0", "description": "Forward latch memory" },
    { "tag": "M1", "description": "Reverse latch memory" }
  ]
}