Well, I am trying make a library for HMI display. display and Arduino comminicate with Serial. So I will so many times Serial port. Generally I will use Serial.write commend. if I examine other libraries, there are lots way to declare serial. Why and which is the best I want to learn.
there I have seen declaring Serial methods.
Method 1
in library .h file
nothing
in library .cpp file
#include <SoftwareSerial.h>
SoftwareSerial SIM(RX_PIN,TX_PIN);
void KapadokyaGSM::basla(){
SIM.begin(9600);
_tampon.reserve(255);
}
Method 2
in library .h file
public:
EasyNex(HardwareSerial& serial);
...
private:
HardwareSerial* _serial;
...
in library .cpp file
EasyNex::EasyNex(HardwareSerial& serial){ // Constructor's parameter is the Serial we want to use
_serial = &serial;
}
void EasyNex::begin(unsigned long baud){
_serial->begin(baud); // We pass the initialization data to the objects (baud rate) default: 9600
delay(100); // Wait for the Serial to initialize
Also I have seen declaring with Stream but now i didnt find example codes. So finally Can anyone tell me what is the best for declearing Serial in library. it can be for only hardware serial or both