aboutsummaryrefslogtreecommitdiffstats
path: root/source/lang/digitalread.rst
blob: 3502587793e5c4ae193cc7c836bbedab078fbe57 (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
52
53
54
55
56
57
58
.. 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


Example
-------

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

    int ledPin = 13;     // LED connected to Maple pin 13
    int buttonPin = 38;  // BUT connected to Maple pin 38

    void setup() {
      pinMode(ledPin, OUTPUT);
      pinMode(buttonPin, INPUT);
    }

    void loop() {
      int val = digitalRead(buttonPin);   // reads the input pin
      digitalWrite(ledPin, val);
    }

Note
----

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

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

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


See Also
--------

-  :ref:`pinMode <lang-pinMode>`
-  :ref:`digitalWrite <lang-digitalWrite>`





.. include:: cc-attribution.txt