Make it a TOGGLE

// WHAT YOU WILL LEARN

One press ON, next press OFF: remember a state in a variable and detect the press.

// LESSON NOTES

Part 7: make your LED a TOGGLE 🔘

Press once → ON. Press again → OFF.

The trick: a bool variable REMEMBERS the state, and ledOn = !ledOn flips it (! means NOT).

But hold the button and it keeps flipping… 😬 The fix: wait until the button is released. One press = one flip.

Related lessons