Go Down

Topic: SoftwareSerial reference instance from sketch in a library? (Read 636 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


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy