Skip to content

Example 02: Digital signal readings

Alexander Spiridonov edited this page Aug 6, 2016 · 12 revisions

Additional documentation for an example supplied with the KeyDetector library that demonstrates use of a library to get digital signal readings.

About

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.

Parts List

  • Arduino UNO or compatible
  • Three momentary switches
  • Three 10kOhm resistors

Schematic

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.

Breadboard

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.

Sketch

Documented sketch is supplied with the library and can be found at "examples/Example-02_Digital/Example-02_Digital.ino".

Run

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.

Clone this wiki locally