Is it possible to make global "defines" that work with libraries?

I am trying to make my application a little more configurable.

My project consists out of a library that use SoftwareSerial. I want to be able to change the pins used by SoftwareSerial from inside my sketch.
Problem is SoftwareSerial only sets its pin with its constructor.

Is there a way that I can do a "Define" in my sketch that applies it to my library that instantiates SoftwareSerial and applies my define at compile time?

Other option I have is to maybe define SoftwareSerial in my main sketch and pass SS to my library.... (Not sure how to thought)
Or Change the SS library to allow for Pin change.(Don't want to move away from using standard libraries.)

Any suggestions would be appreciated, thanks.

You can create a pointer to a SS instance then use "new" or call the begin() or similar. I've done it before but can't remember the syntax offhand so I'll look for some code.

EDIT: Found some code

static SoftwareSerial * _mySs;

_mySs = new SoftwareSerial(rxpin, txpin);
_mySs->begin (baud);
_mySs->write (c);
if (_mySs->available() {
    c = _mySs->read();
}

Rob

nid69ita:
First, if you post your code is more simple to suggest a solution.
Second, you can create a method for your class like Init() or Begin() and ask as parameter the pin for SoftwareSerial.

For example Ethernet class have a constructor but in setup() you must use Ethernet.begin()

This is my library:

I think the issue is the Serial Object being global in the library....
CPP-L4 SoftwareSerial rs485 (RX_PIN, TX_PIN);

Graynomad:
You can create a pointer to a SS instance then use "new" or call the begin() or similar. I've done it before but can't remember the syntax offhand so I'll look for some code.

EDIT: Found some code

static SoftwareSerial * _mySs;

_mySs = new SoftwareSerial(rxpin, txpin);
_mySs->begin (baud);
_mySs->write (c);
if (_mySs->available() {
    c = _mySs->read();
}





_____
Rob

That seems more like what I am after. What is the reason for making it static?

Graynomad:
You can create a pointer to a SS instance then use "new" or call the begin() or similar. I've done it before but can't remember the syntax offhand so I'll look for some code.

EDIT: Found some code

static SoftwareSerial * _mySs;

_mySs = new SoftwareSerial(rxpin, txpin);
_mySs->begin (baud);
_mySs->write (c);
if (_mySs->available() {
    c = _mySs->read();
}





_____
Rob

Works like a charm!!!! Now I can config my pins and not have duplicate code... Developers heaven!!! XD XD XD

Setting up Serial also includes the buffer. When you switch, take care about that or more specifically what is in that or you could end up with funny results.

#defines are processed in order - try

#define MY_DEFINE ...
#include <mylibrary.h>

I not sure but think that works...

The variables should be in the library and extern in the main code. Having the main code set those for the library is kind of putting the cart before the horse.