-
Notifications
You must be signed in to change notification settings - Fork 2
Example 02: Digital signal readings
Additional documentation for an example supplied with the KeyDetector library that demonstrates use of a library to get digital signal readings.
This example shows how KeyDetector can be used to detect single and continuous push-button presses. Pressing button once or keeping it in pressed state continuously will print corresponding message.
- Arduino UNO or compatible
- Three momentary switches
- Three 10kOhm resistors
Schematic is simple. Each switch is connected to the input pin of Arduino using pulldown resistor. You may wish to implement additional debounce filtering to minify chances of false readings at the moment of button press.
Connect one terminal of each momentary switch both to its corresponding Arduino input pin (2, 3, or 4) and to ground through 220Ohm pulldown resistor. Connect the opposite terminal to 5V.
Documented sketch is supplied with the library and can be found at "examples/Example-02_Digital/Example-02_Digital.ino".
After compiling and uploading sketch to Arduino, open Serial Monitor and start pressing the buttons. Message Button X pressed!
(where X
is the name of the button, being A
, B
, or C
) will be printed for each button press. If you press and hold the button in a pressed state for some time, after about 1s message Button X remains pressed
will be printed, and it will be continuously repeated with 0.5s interval while button remains in pressed state.