Go Down

Topic: SoftwareSerial reference instance from sketch in a library? (Read 605 times) previous topic - next topic

renasis

Hello,

I created a SoftwareSerial instance in my main sketch, mymain.ino. I want to reference that instance in an included library. I want to be able to debug the program from a softwareserial port in the main sketch and the library. So, here is what I have, I get an error when I try to DebugPort.print in the .cpp file.

//mymain.ino
#include <SoftwareSerial.h>
#include <MyLibrary.h>
SoftwareSerial DebugPort(2,3);
...
DebugPort.print("something");
...

//mylibrary.cpp
...
DebugPort.print("something");  -->get an error from compiler DebugPort was not declared in this scope
...

Thanks,

-ren





Nick Gammon

Try:

Code: [Select]
//mylibrary.cpp
...
#include <SoftwareSerial.h>

extern SoftwareSerial DebugPort;

...
DebugPort.print("something");  -->get an error from compiler DebugPort was not declared in this scope
...


Not tested though.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

renasis


Go Up