Hello,
I'd like to play with a Serial module (APC220) then I had a look at SoftwareSerial library and some examples on the web.
The thing that surprises me is that very often I can see functions used twice : once for Serial and once for the instantiated object ?
For instance on SoftwareSerial Example we can see :
Serial.println(...);
mySerial.println(...);
or :
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
What is the reason/need to do this twice once for Serial and once for the mySerial ?
On the other I can see the example of available() function which seems do that only once (make more sense to me) :
// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup() {
// define pin modes for tx, rx:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() {
if (mySerial.available()>0){
mySerial.read();
}
}
I read the docs but cannot find explanation on that.
Thanks for your help.
Tom