digitalRead()

[Digital I/O]
unsigned char digitalRead(unsigned short pin);

Description

Reads the value from a specified digital pin.

Parameters

pin: the Custom Element pin you want to read.

Returns

HIGH or LOW.

Example Code

Sets pin 7 to the same value as pin 3.

void setup() {
  pinLabel(7, "OUT");   // sets the pin 7 label to "OUT"  
  pinMode(7, OUTPUT);   // sets the digital pin 7 as output

  pinLabel(3, "IN");    // sets the pin 3 label to "IN" (by default will be an input)
}

void loop() {
  int val = digitalRead(3);   // read the input pin
  digitalWrite(7, val);       // sets the output pin value
}

Notes and Warnings

If the pin is defined as three-state and the ground pin isn’t connected to anything, digitalRead() will always return HIGH.