Loading...

Reference   Language | Libraries | Comparison | Changes

SoftwareSerial: listen()

Description

Enables the selected software serial port to listen. Only one software port can listen at a time.

Syntax

mySerial.listen()

Parameters

mySerial:the name of the instance to listen

Returns

None

Example

#include <SoftwareSerial.h>

// software serial : TX = digital pin 2, RX = digital pin 3
SoftwareSerial portOne(2, 3);

// software serial : TX = digital pin 4, RX = digital pin 5
SoftwareSerial portTwo(4, 5);

void setup()
{
  // Start the hardware serial port
  Serial.begin(9600);

  // Start both software serial ports
  portOne.begin(9600);
  portTwo.begin(9600);

}

void loop()
{
  portOne.listen();

  if (portOne.isListening()) {
   Serial.println("Port One is listening!");
}else{
   Serial.println("Port One is not listening!");
}

  if (portTwo.isListening()) {
   Serial.println("Port Two is listening!");
}else{
   Serial.println("Port Two is not listening!");
}

}
 

See also

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.