aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/lang/api/digitalread.rst
blob: ccf4a4c72c78b07216def7436e7643bf2fc4abab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
.. highlight:: cpp

.. _lang-digitalread:

digitalRead()
=============

Reads the value from a specified digital pin, either :ref:`HIGH
<lang-constants-high>` or :ref:`LOW <lang-constants-low>`.

Library Documentation
---------------------

.. doxygenfunction:: digitalRead

Discussion
----------

If the pin isn't connected to anything, ``digitalRead()`` can return
either HIGH or LOW (and this will change in a way that seems random).

Example
-------

The following example turns the LED on or off when the button is pressed::

    void setup() {
      pinMode(BOARD_LED_PIN, OUTPUT);
      pinMode(BOARD_BUTTON_PIN, INPUT);
    }

    void loop() {
      int val = digitalRead(BOARD_BUTTON_PIN);   // reads the input pin
      togglePin(BOARD_LED_PIN, val);
    }

Arduino Compatibility
---------------------

The Maple version of ``digitalRead()`` is compatible with Arduino.

See Also
--------

- :ref:`BOARD_BUTTON_PIN <lang-board-values-but>`
- :ref:`lang-isButtonPressed`
- :ref:`lang-pinmode`
- :ref:`lang-digitalWrite`
- :ref:`lang-togglepin`

.. include:: /arduino-cc-attribution.txt