digitalRead()

Description

Reads the value from a specified digital pin, either HIGH or LOW.

 

Syntax
digitalRead(pin)

 

Parameters

pin: the number of the digital pin you want to read (int)

 

Returns

HIGH or LOW

 

Example

Sets pin 13 to the same value as pin 7, declared as an input.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

int ledPin = 13; // LED connected to pin 13

int inPin = 7;   // The button is connected to pin 7

int val = 0;     // Use the val variable to store the read value

 

void setup()

{

  pinMode(ledPin, OUTPUT);      // Set digital pin 13 as output

  pinMode(inPin, INPUT);      // Set digital pin 7 as input

}

 

void loop()

{

  val = digitalRead(inPin);   // Read input pin

  digitalWrite(ledPin, val);    // Set the LED to the button's value

}

 

Note

If the pin isn't connected to anything, digitalRead() can return either HIGH or LOW (and this can change randomly).

Unlike Arduino, the analog input pins (referred to as A0, A1, etc) of 86Duino cannot be used as digital pins.

 

See also

pinMode()
digitalWrite()


 

Language Reference 

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.