Framework (A-Z)

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

Class

Serial

Name

read()

Examples
int val;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Set the analog output pin 0 to the value in val
  if (Serial.available() > 0) {
    val = Serial.read();
  }
  analogWrite(0, val);  
}
Description Returns the next byte that's waiting in the buffer. Returns -1 if there is no byte, although this should be avoided by first checking available() to see if data is available.
Syntax
serial.read()
Parameters
serial The hardware serial port, it can be Serial, Serial1 or if available Serial 2, Serial3.
Returns int
Usage Application
Updated on July 07, 2011 11:08:55pm PDT

Creative Commons License