AdvancedOne-shot / toggle~20 min

One Button Toggle (edge contacts)

One push button: press → lamp ON, press again → lamp OFF. Sounds trivial, defeats most beginners. The trick is a rising-edge contact plus a snapshot of the lamp's state taken BEFORE you change it.

Your goal

  • Each press of Btn toggles the Lamp (off→on, on→off).
  • HOLDING the button must toggle exactly once not flicker every scan.
  • The order of your rungs is the whole solution.
Stuck? Show hints (3)
  1. The |P| contact conducts for exactly ONE scan when its tag goes false→true. That kills the hold-flicker problem.
  2. But if you latch AND unlatch on the same edge, the second rung undoes the first in the same scan. You need a snapshot.
  3. Rung 1: NO Lamp → OTE WasOn (capture the state BEFORE changing it). Rung 2: |P| Btn AND NC WasOn → OTL Lamp. Rung 3: |P| Btn AND NO WasOn → OTU Lamp.

The snapshot-then-act pattern you'll reuse it constantly.

I/O for this exercise

Inputs
BtnToggle push button
Outputs
LampLamp
Internal coils
WasOnSnapshot: lamp state at scan start
Loading the editor…