filmov
tv
Arduino Lesson 7 - Debounce Button, Use Button as Toggle Switch

Показать описание
I found that I was experiencing "chatter" occasionally when pressing the pushbutton. Sometimes I would press the button and the LEDs would flash and stay on. Sometimes I would release the button and the LEDs would stay lit. Not cool.
In this lesson, I show you how I "debounced" the button in code by checking how long the button has been pressed or released. This allows us to be sure that the button state has actually changed before turning the LEDs on or off.
I also changed the code to have the button act as a toggle switch. Before, I had to hold the button pressed to have the LEDs flash, and when I released it, the LEDs would turn off. What I really wanted was to have the LEDs stay on when I pressed and released the button once, and then turn off when I pressed it again. This is the action you typically in a toggle switch such as the light switch on your wall. Enjoy!
In this lesson, I show you how I "debounced" the button in code by checking how long the button has been pressed or released. This allows us to be sure that the button state has actually changed before turning the LEDs on or off.
I also changed the code to have the button act as a toggle switch. Before, I had to hold the button pressed to have the LEDs flash, and when I released it, the LEDs would turn off. What I really wanted was to have the LEDs stay on when I pressed and released the button once, and then turn off when I pressed it again. This is the action you typically in a toggle switch such as the light switch on your wall. Enjoy!