Hi Martin,
To allow multiple users of an interface over different files, you can use extern as you say. In the following example, the objects are created and pins are assigned in one place (the .cpp file), and the externs in the header file allow any other file to #include them and therefore get access to them.
[interfaces.cpp]
#include "interfaces.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
[interfaces.h]
#ifndef INTERFACES_H
#define INTERFACES_H
#include "mbed.h"
extern DigitalOut led1;
extern DigitalOut led2;
extern DigitalOut led3;
extern DigitalOut led4;
#endif
See the whole program for a full example:
GlobalPinAssignments
But i'm not sure if this exactly answers your question? If not, can you provide the question by way of an example?
Simon
Hi Everyone,
I have a question on the Mbed pin assignments. I am writing a program to interface with an ADC. I have split the program over 3 files, the first sets up the ADC, the second reads it and the third (main.cpp) takes in tha data and prints it to a pc.
I know I can use global variables by using the extern declaration, but is there some way I can make global pin assignments as the same pins are used in the setting up and reading of the ADC, it seems a bit silly to have to redeclare them all using different names!
Regards
Martin