Hello,
This is my first post in the Arduino forum. I've done C before over the years, but am quite new to C++ and finding some of the syntax a little tricky, though I'm enjoying the experience overall.
I am working on application that sends data across radio links, and it is working fine and seems to be very reliable.
The next step is to turn this code into a library. I followed the How to make an Arduino Library tutorial and it all worked perfectly, so I'm very enthusiastic!
I have all of the interfaces/methods planned out (the application is already written and working as a sketch, so this is mainly a "porting" exercise). However, one of the this facilities I would like to implement is a facility such that the object instance knows which serial port to use. The serial port to use will be defined at the application level, and the object instance will be told which serial port it should be use.
Here's some example code which illustrates what I'm trying to do; unfortunately the code doesn't compile. The compiler gives the following error:
error: 'Serial' does not name a type
Serial _serialRef;
^
This error refers to the line immediately after the private: keyword, below.
class Test
{
private:
Serial _serialRef;
public:
Test
{
}
setSerial(Serial serialObject)
{
_serialRef=serialObject;
}
sendText(char *someText)
{
_serialRef.println(someText);
}
};
Application-level code will set the serial port to be used, using something like the following:
Serial.begin();
Test testObj;
testObj.setSerial(&Serial);
testObj.sendText("Hello World!");
Note: I've not put the above code into a library. At the moment, I added a simple test class to my sketch, to try and get the syntax correct.
I'm clearly missing something (probably) trivial. Any help/pointers (ha! Pointers!
) would be much appreciated.
Regards
Mark