Arduino参考

Arduino参考 > Libraries > SoftwareSerial > isListening()

SoftwareSerial.isListening()

Tests to see if requested software serial object is actively listening.

Syntax

mySerial.isListening()

Parameters

None.

Returns

Boolean.

Example

#include <SoftwareSerial.h>

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

void setup() {
    // Set the baud rate for the Serial port
    Serial.begin(9600);

    // Set the baud rate for the SerialSoftware object
    portOne.begin(9600);
}

void loop() {
    if (portOne.isListening()) {
        Serial.println("portOne is listening!");
    }

    // ...