6 years, 7 months ago.

Creating a library from two programs

There are two programs I wills like to run on an LPC1768 board. The idea is to switch between the two programs using a toggle switch. I understand both programs need to be compiled into one binary somehow.

This is the first program https://developer.mbed.org/users/Just4pLeisure/code/Just4Trionic/

And this is the second program https://developer.mbed.org/users/petter/code/Saab-BT/

Not sure how you do this. I know each program has a main.cpp and I'm not sure how to change the programs so that they could be called from a new main.cpp program based on the state of a SPST toggle switch.

1 Answer

6 years, 5 months ago.

I only glanced at the programs, and what comes to mind is that you could put something at the top of main:

#include "mbed.h"

DigitalIn WhichProg(PXX);

...
void main(void) {
    while (1) {
        if (WhichProg) {
            // Prog 1 stuff here
        } else {
            // Prog 2 stuff here
        }
    }
}

This would let you change progs on the fly, but it doesn't address the issue of initialized data between the two. Remove the while loop from that location if you only need to switch on a reset.