Arduino参考

Arduino参考 > Libraries > SoftwareSerial > peek()

SoftwareSerial.peek()

Return a character that was received on the RX pin of the software serial port. Unlike read(), however, subsequent calls to this function will return the same character. Note that only one SoftwareSerial object can receive incoming data at a time (select which one with the listen() function).

Syntax

mySerial.peek()

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.peek();
}