Libraries alternatives

Hi there,

I have code that is the same for multiple boards. Each of them is exactly identical, only their ID varies. They all send data to a central devices via bluetooth. That results in the need of identifying. So, though the code is the same, the ID is the only thing that changes between them.

Is there an easy way to keep the maintenance for the code to a minimum, by just having one instance of the main code?

I envision something like this:

// Main uploaded sketch:

bool a;
int i;
float x;
char c;


void setup() {

CallSetup(a, i, x, c);

}

void loop() {

CallLoop(a, i, x, c);

}

Libraries do that, but mostly in a way, that would be effortful to convert all of my already fully working code. - Especially because I have a trazillion different variables and if they change over time, I'd again increase the maintenance effort...

Or can I save them as privats of the class? are those being stored throughout the loops on arduinos?

Thanks for any input!

Which Arduino board are you using?

Libraries do that, but mostly in a way, that would be effortful to convert all of my already fully working code.

TELL ME ABOUT IT! :confused:

I tried to do the same thing and broke perfectly good code in so many ways. I compromised and have a file called 'common.ino' in each sketch. Common is exactly the same in every one, so if I change it I can just copy and paste it to the others.

Relykaa:
Hi there,

I have code that is the same for multiple boards. Each of them is exactly identical, only their ID varies. They all send data to a central devices via bluetooth. That results in the need of identifying. So, though the code is the same, the ID is the only thing that changes between them.

Is there an easy way to keep the maintenance for the code to a minimum, by just having one instance of the main code?

Write in your code:

#define ID xxxxx

or better yet make it a const variable of some appropriate type

 const int ID = 123;

Where the xxxxx is your ID. Code everything but never refer to the ID in code by any other name. Only use the name of your one variable that holds the ID.

Now when you want to use it for another board all you have to do is change that one line of code.

You could also store ID info in EEPROM. But, you'd need to add code that would check if it's there first and if not, somehow prompt the user to supply it.

Simple enough. Store the ID in EEPROM.

When you create a new board for your system you have a simple sketch which allows you to create and program the ID value into EEPROM. You run this once and create the ID for the new board. Then you load the production code into your new board which reads the ID from EEPROM as part of it's setup() function.

Every board has a different ID stored in EEPROM so the production code can be identical for all boards.

Two bytes of EEPROM would give you 65,536 possible board ID's which is probably enough to be going on with.

Ian