Arduino参考

Arduino参考 > Libraries > SoftwareSerial > read()

SoftwareSerial.read()

Return a character that was received on the RX pin of the SoftwareSerial objecto. Note that only one SoftwareSerial object can receive incoming data at a time (select which one with the listen() function).

Syntax

mySerial.read()

Parameters

None.

Returns

The character read or -1 if none is available.

Example

#include <SoftwareSerial.h>

// Set up a new SoftwareSerial object with RX in digital pin 10 and TX in digital pin 11
SoftwareSerial mySerial(10, 11);

void setup() {
    // Set the baud rate for the SerialSoftware object
    mySerial.begin(9600);
}

void loop() {
    char c = mySerial.read();
}