aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/arduino/digitalread.rst
blob: daf04f8999e3ba59753fa926c28ba2af558fbe9e (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
59
60
61
.. highlight:: cpp

.. _arduino-digitalread:

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

Description
-----------

Reads the value from a specified digital pin, either :ref:`HIGH
<arduino-constants-high>` or :ref:`LOW <arduino-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 <arduino-pinMode>`
-  :ref:`digitalWrite <arduino-digitalWrite>`





.. include:: cc-attribution.txt