Example of an "extern" declaration to reuse a global variable defined in one file in another file.
Dependencies: mbed
Revision 0:bc708d703171, committed 2015-09-23
- Comitter:
- bjo3rn
- Date:
- Wed Sep 23 20:45:28 2015 +0000
- Commit message:
- initial commit;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Sep 23 20:45:28 2015 +0000 @@ -0,0 +1,13 @@ +#include "mbed.h" +#include "myWait.h" +DigitalOut redLed(LED_RED); +DigitalOut greenLed(LED_GREEN); + +int main() { + while(1) { + redLed = 1; + myWait(0.2); + redLed = 0; + myWait(0.2); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 23 20:45:28 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myWait.cpp Wed Sep 23 20:45:28 2015 +0000 @@ -0,0 +1,12 @@ +#include "mbed.h" +#include "myWait.h" + +// extern declares that the global variable greenLed is defined in a different source file +extern DigitalOut greenLed; + +// definition of our custom wait function +void myWait(float t) { + greenLed=0; //turn on + wait(t); //wait + greenLed=1; //turn off +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myWait.h Wed Sep 23 20:45:28 2015 +0000 @@ -0,0 +1,7 @@ +#ifndef MYWAIT_H +#define MYWAIT_H + +//declare a custom wait function +void myWait(float t); + +#endif \ No newline at end of file