Pages: [1]   Go Down
Author Topic: SoftwareSerial reference instance from sketch in a library?  (Read 527 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 85
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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




Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try:

Code:
//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.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 85
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick,

Thanks, works well.

-ren
Logged

Pages: [1]   Go Up
Jump to: