Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 6 months ago.
How to pass AnalogOut pin name to a constructor?
I have posted an example program I wrote. The entire point is to pass a PinName to a class constructor. It seems that I can pass the pinName for a digital pin but not an analog pin.
Likely I've got a dumb typo someplace and I can't see it. But the error I get at line #31 is that "AnalogOut" is not defined. This is odd because when I reference _AAA I don't get an undefined symbol error. I also get an error on line #16 "expecting type"
Also odd because all seems to be well with DigitalOut on the line above.
test passing pin names
#include "mbed.h"
class TestPassingPinNames {
public:
// In default constructor the pin names default
TestPassingPinNames() {
TestPassingPinNames(PA_7, PA_6);
setpins();
}
// In this constructor the user can specify the pin names
TestPassingPinNames( PinName DDDpin,
PinName AAApin) {
_DDD = new DigitalOut(DDDpin);
_AAA = new AnalogOut(AAApin);
setpins();
}
void resetpins() {
*_DDD = 0;
*_AAA = 0.0f;
}
private:
void setpins() {
*_DDD = 1;
*_AAA = 0.5f;
}
DigitalOut * _DDD;
AnalogOut * _AAA;
};
int main() {
TestPassingPinNames PinSet1;
TestPassingPinNames PinSet2(PA_4, PA_3);
PinSet1.resetpins();
PinSet2.resetpins();
}
1 Answer
7 years, 6 months ago.
Hello Chris,
I think the code is OK but the target board you are trying to compile for doesn't support AnalogOut peripheral.