ezButton Library - Single Button Events Example
|1||×||Arduino UNO or Genuino UNO|
|1||×||USB 2.0 cable type A/B|
|1||×||(Optional) 9V Power Adapter for Arduino|
|1||×||(Recommended) Screw Terminal Block Shield for Arduino Uno|
This image is created using Fritzing. Click to enlarge image
- Install ezButton library. See How To
- Connect Arduino to PC via USB cable
- Open Arduino IDE, select the right board and port
- On Arduino IDE, Go to File Examples ezButton 02.SingleButtonEvents example
- Click Upload button on Arduino IDE to upload code to Arduino
- Open Serial Monitor to see result:
- Press the button and then release
※ NOTE THAT:
Even you pressed and released the button only once, the output in Serial Monitor may show several pressed and release events. This is the normal behavior of the button. This behavior is called the “chattering phenomenon”. You can learn more in Arduino - Button Debounce tutorial.
To make it much easier, we can use the debouce function of this library. See Button debounce example with library.
Read the line-by-line explanation in comment lines of source code!