One button for multiple functions
I want to use only one button for multiple purposes. For example, the first press, do task 1. The second press, do task 2. The third presss, do the task 3. This process is repeated.
In general, there are two ways for a single button to do multiple functions:
- If there are only two functions, we can use the long press and short press to do the two seperate tasks.
- If there are two or more functions, we can use the button press's count to do multiple tasks.
The below example shows how to use a single button to do three different tasks based on the press's count.
The wiring diagram for above code:
This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
The above code uses the ezButton library, you can see how to install the library
Hardware for above code
|1 × Arduino UNO Buy on Amazon
|1 × USB 2.0 cable type A/B Buy on Amazon
|1 × Button Buy on Amazon
|1 × Breadboard Buy on Amazon
|1 × Jumper Wires Buy on Amazon