Skip to content

Commit b079582

Browse files
author
mjm2017
authored
Deinitialize the pin definition
Without freeing the DAC, the pin will continue to be configured as DAC. Which make it impossible to change it from Analogout to anything else. Check this code that allow you to change the AnalogOut to DigitalOut <<code>> #include "mbed.h" class myAnalog : public AnalogOut{ public: myAnalog(PinName myname); ~myAnalog(); PinName _myname; }; myAnalog::myAnalog(PinName myname):AnalogOut(myname), _myname(myname){ ; } myAnalog::~myAnalog(){ analogout_free(&this->_dac); } myAnalog *x=0; DigitalOut *xx=0; void do_something_analog() { x=new myAnalog(PA_4); double g=0.0; while(g<0.5){ x->write(g); g=g+0.1; wait_ms(50); } if (x!=0){ delete x; x=0; } } void do_something_digital() { xx=new DigitalOut(PA_4); for(int i=0;i<10;i++){ *xx = 1; wait_ms(50); *xx = 0; wait_ms(50); } if (xx!=0){ delete xx; xx=0; } } int main() { printf("\nAnalog loop example\n"); while(1) { do_something_digital(); do_something_analog(); } } <</code>>
1 parent 279925b commit b079582

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/AnalogOut.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class AnalogOut {
138138

139139
virtual ~AnalogOut()
140140
{
141-
// Do nothing
141+
// deinitialize the pin configuration totally. This should allow chaining the definition of the pin
142+
analogout_free(&this->_dac);
142143
}
143144

144145
protected:

0 commit comments

Comments
 (0)