Hey All

I am trying to figure out how to use references with the hardware serial ports.
// File: sketch.ino
#include <Arduino.h>
#include <TestSerial.h>
TestSerial testSerial(Serial);
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
byte iByte = Serial.read();
testSerial.sayit();
}
}
// File: TestSerial.h
#ifndef TestSerial_h
#define TestSerial_h
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
public:
TestSerial(HardwareSerial& localSerial);
void sayit();
};
#endif
// File: TestSerial.cpp
#include <Arduino.h>
#include <TestSerial.h>
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
}
void TestSerial::sayit() {
privateSerial.println("HELLO WORLD!");
}
Any ideas?