class TestSerial {
private:
// Here is where I want to declare whatever it is I need to declare to get the reference supplied by the constructor
// but I have no idea what to do. I have tried:
HardwareSerial& privateSerial;
// Which generates a compiler error cannot convert 'HardwareSerial' to 'HardwareSerial*' in assignment
TestSerial::TestSerial(HardwareSerial& localSerial) {
// Here is where I want to put the reference 'localSerial' into the 'privateSerial'
// I tried:
privateSerial = localSerial; - No go because of compiler error
}
I thank you guys for being patient with me, however, I am still a little stumped.
I need my class to contain all 4 hardware serial ports as references so that I can work with them locally inside the class.
Your example for a single reference worked fine for a singe serial port reference.
How do I get the constructor to deal with all of the references I pass to it?
IE:
// Header file
class MyClass {
private:
HardwareSerial& portA, portB, portC, portD;
public:
MyClass(HardwareSerial& sRefA, HardwareSerial& sRefB, HardwareSerial& sRefC, HardwareSerial& sRefD) {
// How to assign the references passed to the constructor to the local class objects?
//
}
// Or deal with them in the source file constuctor...
// Source file #include <MyClass.h>
MyClass::MyClass(HardwareSerial& sRefA, HardwareSerial& sRefB, HardwareSerial& sRefC, HardwareSerial& sRefD) {
portA = sRefA; // Does not work
portB = sRefB;
portC = sRefC;
portD = sRefD;