Programming a Tact Switch

Hi! I'm a newbie in using Arduino (and also in programming actually).

So I've tried some of the built-in experiments and came across the tact switch, I just got curious, how do you program a tact switch so that the LED will remain lit up even when you don't press it anymore? And once you do the LED will turn off.

Answers and explanations are greatly appreciated. Thanks! :slight_smile:

Test for when the switch becomes pressed. Toggle the LED. Wait 10 milliseconds to debounce the switch. Test for when the switch becomes released. Repeat.

Knowing how it has changed requires that you keep the last switch state in a variable.

Look for a key-press (or release) not the key-state (easy with a library, for example Bounce2),

then toggle the LED on each detected keypress.


Change it from "switch the LED every 4 pushes" to "switch the LED every 1 push" by changing '4' to '1' in one place.

how do you program a tact switch

It is highly unlikely that the switch IS programmable. Give it up unless your is.

The code in Several Things at a Time includes a button that does what you want.