← All exercises

Press-Toggle Lamp

medium

Flip the lamp state on each rising edge of the push button.

What it teaches

Each press flips the lamp: off → on → off → on. Two steps make it work: catch the moment the button goes down — its rising edge, the pulse you just built — and on that single moment invert the lamp's own remembered state. Holding the button does nothing; only the press edge counts. The basic toggle behind desk lamps and software buttons.

Inputs and outputs

TagTypeDefaultDescription
In_ButtonBOOLPush button input
Out_LampBOOLLamp drive signal

Required behavior

  • Lamp output inverts its current state on each rising edge of the push button input.