{
  "version": 2,
  "name": "Rising Edge / One-Shot: P and N Contacts (Control Panel)",
  "exported": "2026-11-16T00:00:00.000Z",
  "notes": "Control Panel scene example for the rising edge / one-shot tutorial. X1 = Start (N.O.), X2 = Stop (N.C., ON when not pressed), X3 = Jog (N.O.), used here as the Count button. X4 = Reset Counts, clicked on the I/O tab (not part of the scene). D1 = presses counted with a plain XIC contact (wrong: INC runs every 100 ms scan, so a 4 s hold adds 40). D2 = presses counted with a P contact (one per press). D3 = releases counted with an N contact. CT1 = the same button on a CTU (counters already count edges). C1 = Start one-shot. Y1 = motor run light, push-on / push-off from the Start button. D4 = Stop presses: X2 is N.C., so a press is an ON to OFF change and is caught with an N contact. Rungs 7 and 8: Reset Counts (X4) fills D1 to D4 with 0 and resets CT1.",
  "program": [
    {
      "id": 1,
      "rn": 0,
      "comment": "THE BUG — XIC on the Count button (X3) feeds INC. INC adds 1 on EVERY scan the rung is true: hold the button 4 s and D1 jumps by 40",
      "elements": [
        {
          "id": 101,
          "kind": "contact",
          "type": "XIC",
          "addr": "X3"
        },
        {
          "id": 102,
          "kind": "block",
          "type": "INC",
          "addr": "D1",
          "pre": 0,
          "dt": "INT"
        }
      ]
    },
    {
      "id": 2,
      "rn": 1,
      "comment": "THE FIX — a P (rising edge) contact passes power for ONE scan when X3 goes OFF to ON. One press, one count in D2",
      "elements": [
        {
          "id": 103,
          "kind": "contact",
          "type": "P",
          "addr": "X3"
        },
        {
          "id": 104,
          "kind": "block",
          "type": "INC",
          "addr": "D2",
          "pre": 0,
          "dt": "INT"
        }
      ]
    },
    {
      "id": 3,
      "rn": 2,
      "comment": "N (falling edge) — one scan when X3 goes ON to OFF. D3 counts releases, not presses",
      "elements": [
        {
          "id": 105,
          "kind": "contact",
          "type": "N",
          "addr": "X3"
        },
        {
          "id": 106,
          "kind": "block",
          "type": "INC",
          "addr": "D3",
          "pre": 0,
          "dt": "INT"
        }
      ]
    },
    {
      "id": 4,
      "rn": 3,
      "comment": "COUNTERS ALREADY COUNT EDGES — the same button on a CTU needs no P contact. CT1 matches D2",
      "elements": [
        {
          "id": 107,
          "kind": "contact",
          "type": "XIC",
          "addr": "X3"
        },
        {
          "id": 108,
          "kind": "block",
          "type": "CTU",
          "addr": "CT1",
          "pre": 100
        }
      ]
    },
    {
      "id": 5,
      "rn": 4,
      "comment": "START ONE-SHOT — C1 is ON for exactly one scan each time Start (X1) is pressed",
      "elements": [
        {
          "id": 109,
          "kind": "contact",
          "type": "P",
          "addr": "X1"
        },
        {
          "id": 110,
          "kind": "output",
          "type": "OTE",
          "addr": "C1"
        }
      ]
    },
    {
      "id": 6,
      "rn": 5,
      "comment": "PUSH ON / PUSH OFF — each Start pulse flips Y1 (pulse AND off, or no pulse AND on). Stop (X2, N.C.) always drops it",
      "elements": [
        {
          "id": 111,
          "kind": "parallel",
          "branches": [
            [
              {
                "id": 112,
                "kind": "contact",
                "type": "XIC",
                "addr": "C1"
              },
              {
                "id": 113,
                "kind": "contact",
                "type": "XIO",
                "addr": "Y1"
              }
            ],
            [
              {
                "id": 114,
                "kind": "contact",
                "type": "XIO",
                "addr": "C1"
              },
              {
                "id": 115,
                "kind": "contact",
                "type": "XIC",
                "addr": "Y1"
              }
            ]
          ]
        },
        {
          "id": 116,
          "kind": "contact",
          "type": "XIC",
          "addr": "X2"
        },
        {
          "id": 117,
          "kind": "output",
          "type": "OTE",
          "addr": "Y1"
        }
      ]
    },
    {
      "id": 7,
      "rn": 6,
      "comment": "STOP PRESSES — X2 is N.C., so pressing Stop turns X2 OFF. The press is a FALLING edge: use N, not P",
      "elements": [
        {
          "id": 118,
          "kind": "contact",
          "type": "N",
          "addr": "X2"
        },
        {
          "id": 119,
          "kind": "block",
          "type": "INC",
          "addr": "D4",
          "pre": 0,
          "dt": "INT"
        }
      ]
    },
    {
      "id": 8,
      "rn": 7,
      "comment": "RESET COUNTS — X4 (click it on the I/O tab) fills D1 to D4 with 0",
      "elements": [
        {
          "id": 120,
          "kind": "contact",
          "type": "XIC",
          "addr": "X4"
        },
        {
          "id": 121,
          "kind": "block",
          "type": "FLL",
          "addr": "D1",
          "pre": 0,
          "src": "0",
          "len": 4,
          "dt": "INT"
        }
      ]
    },
    {
      "id": 9,
      "rn": 8,
      "comment": "RESET COUNTS — X4 also clears CT1. A counter only goes back to zero with a RES",
      "elements": [
        {
          "id": 122,
          "kind": "contact",
          "type": "XIC",
          "addr": "X4"
        },
        {
          "id": 123,
          "kind": "block",
          "type": "RES",
          "addr": "CT1",
          "pre": 0
        }
      ]
    }
  ],
  "comments": {
    "X1": "Start PB",
    "X2": "Stop PB (N.C.)",
    "X3": "Count PB (Jog)",
    "X4": "Reset Counts",
    "C1": "Start One-Shot",
    "Y1": "Motor Run",
    "D1": "Count: XIC (bug)",
    "D2": "Count: P (fix)",
    "D3": "Count: N (release)",
    "D4": "Stop Presses",
    "CT1": "Count: CTU"
  }
}