The instantiation of the Zigee class takes place before the Setup() function runs, which is where we usually set up the serial port (e.g. 'Serial.begin(38400)'). Therefore how do I pass an instance of the serial port to the Zibee constructor when the serial port is yet to be set up?
You can't. That was my point. You'll notice in the Serial class that you set the baud rate AFTER the instance has been created. You need to do the same with your class. After the Zigbee instance has been created, call the (not currently defined) begin() method to pass it the Serial instance to use.
You mention - "Then, use _Serial.read(), _Serial.available(), etc. elsewhere in your code."
Do I use these within the calling code, within the class (or object), or both?
You class will have a private Serial reference field named _Serial. So, only your class can refer to that name.
Your class' header file should have public methods:
Zigbee ();
~Zigbee ();
void begin(Serial &serIn);
It should have at least one private field:
Serial &_Serial;
The constructor does nothing:
Zigbee::Zigbee()
{
}
The begin method does stuff:
void Zigbee::begin(Serial &serIn)
{
_Serial = serIn;
_Serial.begin(38400);
_Serial.println("Ready to Rip!");
}
Does this mean that I shouldn't pass the Serial instance to the constructor? Should it only be passed to a 'begin' method after the instantiation of the Zigbee object?
That's exactly what I mean. Since the Serial object may be created before or after the Zigbee object, the Zigbee object can not call the Serial.begin method. There may not be a Serial instance, yet.