Reference for Wiring version 0024+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

digitalRead()

Examples
int inpin = 0;
int outpin = 1;
int val = 0;

void setup() {
  pinMode(inpin, INPUT); 
  pinMode(outpin, OUTPUT);
}

void loop() {
  val = digitalRead(inpin);
  if(val == HIGH) 
  {
    digitalWrite(outpin, HIGH);
  } else {
    digitalWrite(outpin, LOW);
  } 
}
Description The digitalRead() method reads the value of a digital input pin.
Syntax
digitalRead(pin)
Parameters
pin int
Returns int
Usage Application
Related INPUT
OUTPUT
HIGH
LOW
digitalWrite()
pinMode()
Updated on November 01, 2009 11:25:40pm PST

Creative Commons License