Serial.read()

From Microduino Wiki
Revision as of 09:32, 11 August 2016 by 172.31.23.3 (talk) (Created page with "Read the serial port data, and read() inherits the utility classes from Stream. *'''Syntax''':<br> <pre style="color:green"> Serial.read() </pre> microduino core only: Ser...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Read the serial port data, and read() inherits the utility classes from Stream.

  • Syntax
Serial.read()

microduino core only:

Serial.read()

Serial1.read()

  • Parameters

No

  • Returned valuse

The first byte can be read on the serial ports is of (if there is no data can be read, return -1)- int type.

  • Example
int incomingByte = 0;   // used to store the data read from serial ports

void setup() {
        Serial.begin(9600);     // open the serial port, and set the speed as 9600 bps
}

void loop() {

        // send data only when receiving data
        if (Serial.available() > 0) {
                // read the incoming bytes
                incomingByte = Serial.read();

                // indicate the data you receive
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

[Return to Arduino Syntax Manual]