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
// NEWSLETTER · FREE
Get new lessons + early access to the full course
One email when new lessons drop. No spam, unsubscribe any time.
✓ You're on the list. Check your inbox to confirm.
By joining you agree to the privacy policy.




