Suppose you want to split this program (main.cpp) into 2 parts:
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
You could have one file (main.cpp) like this:
#include "mbed.h"
DigitalOut myled(LED1);
extern void FlashLed( void );
int main() {
while(1) {
FlashLed();
}
}
and the other (Flash.cpp) like this:
#include "mbed.h"
extern DigitalOut myled;
void FlashLed( void ) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
This isn't great programming style, but it does work. A better style would be to use a header (.h) file containing a definition for FlashLed. The key thing here is the use of the keyword "extern". Essentially it means "I want you to know about a variable or function like this, but it isn't declared here, it is declared in another file". If you want your program to compile and link properly then everything you declare as extern (and you can do this in as many files as you like) must be declared somewhere else, once, and not as extern. Google "C extern" for more details.
Hello
I have the problem to split my programm in more files. I dont exactly how that goes. I have allways a fault because my digital In/Outputs are multy declarated.
Have sombody and good explication and pherhaps a example file?
Thanks for Help Daniel