zephyr/samples/basic/button
Marti Bolivar 27e5dd131f doc: s/device tree/devicetree/
DTSpec writes this as a single word, presumably to make it easier to
grep for / more precise. Follow along in the rest of the docs now that
our main DT docs page agrees with this usage.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-10-08 11:53:40 +02:00
..
src sample: button: Fix format specifier 2019-07-31 17:11:19 +02:00
CMakeLists.txt license: cleanup: add SPDX Apache-2.0 license identifier 2019-04-07 08:45:22 -04:00
README.rst doc: s/device tree/devicetree/ 2019-10-08 11:53:40 +02:00
prj.conf samples: move basic samples to samples/basic 2016-10-27 22:14:31 +00:00
sample.yaml dts: Rename DT_.*_GPIO_* to DT_.*_GPIOS_* 2019-06-27 13:02:34 -05:00

README.rst

.. _button-sample:

Button demo
###########

Overview
********

A simple button demo showcasing the use of GPIO input with interrupts.

Requirements
************

The demo assumes that a push button is connected to one of GPIO lines. The
sample code is configured to work on boards with user defined buttons and that
have defined the SW0_* variables.

To use this sample, you will require a board that defines the user switch in its
header file. The :file:`board.h` must define the following variables:

- SW0_GPIO_NAME (or DT_ALIAS_SW0_GPIOS_CONTROLLER)
- DT_ALIAS_SW0_GPIOS_PIN

Alternatively, this could also be done by defining 'sw0' alias in the board
devicetree description file.


Building and Running
********************

This sample can be built for multiple boards, in this example we will build it
for the nucleo_f103rb board:

.. zephyr-app-commands::
   :zephyr-app: samples/basic/button
   :board: nucleo_f103rb
   :goals: build
   :compact:

After startup, the program looks up a predefined GPIO device, and configures the
pin in input mode, enabling interrupt generation on falling edge. During each
iteration of the main loop, the state of GPIO line is monitored and printed to
the serial console. When the input button gets pressed, the interrupt handler
will print an information about this event along with its timestamp.