Modify Value within included library

Hello, this may end up being a very naive question but here goes!

I am working on a project and wanting to know if there is a way to modify a value that is in the library I am including?

in my script i have #include "Tlc5940.h"

In that library is a file called tlc_config.h and it has a value NUM_TLCS that is used to tell the Arduino how many chips are daisy chained together. What I would like to do is have some code in my program that would modify that value based on an input. So something like, "If Pin 3 is HIGH then make NUM_TLCS equal 3". I am planning more to use a value controlled by a POT, but I can handle that part. I just need to know if it is possible for my program script to modify the value in the included library.

Sorry if this is confusing, I am still fairly new to the Arduino world. I will be glad to provide any more details that I can.

Thanks in advance for an help!!

Alex

If NUM_TLCS is a #define then it is not possible. These are evaluated to constants at compile time and so cannot be changed during execution.

You could however change the #define to a variable, such as "byte NUM_TLCS = 0". Then you could simply change this value as any variable. Be careful though, there may be some parts of the library that expect a constant and simply changing the value as a variable would have unexpected consequences.

Tom, thanks for the quick reply!

NUM_TLCS is a #define. :(

Could you please explain a little bit more about changing it? I tried changing the line in the library from:

#define NUM_TLCSĀ  2

to:

byte NUM_TLCS = 2

However I am a little unclear how to reference and modify that in my script? Sorry if that is a really stupid question, but my knowledge is still very limited in the Arduino world.

It is in the header file, which is included, so just use it like any other variable.

EDIT: As I suspected however, this won't work. In the TLC5940.cpp file you will find this line:

uint8_t tlc_GSData[NUM_TLCS * 24];

That number is expected to be a compile time constant, not a variable. It may work if you replace the line above with a constant number which is the maximum you will ever have and then you should be able to make NUM_TLCS variable.

Why are you trying to change the number?

I am using these to make long LED light bars. And depending where I am setting them up the total # of bars will vary. Each light bar will have a TLC5940 in it and they will all connect back to an Arduino. I was hoping to be able to modify that so I don't have to always have a computer to modify the NUM_TLCS at each set-up.

Since I am planning to have the TLC run different schemes with the lights, an incorrect NUM_TLCS value could cause the appearance to be off. (Chasing type effects for example).