5 years, 11 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

5 years, 11 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.

Accepted Answer

Thanks. I had hoped I made a stupid mistake as they are so easy to fix. I change "AnalogOut" to read "PwmOut" and all is now well.

I use to many different platforms.

posted by Chris Albertson 26 May 2018