6 years, 8 months ago.

Is there a way to change a pin declaration?

I have a pin that is normally declared as a SPI port. Later on, under certain conditions, I'd like to change it to a PwmOut. Anyone know how to accomplish this?

1 Answer

6 years, 7 months ago.

With most interfaces you can just re-declare the pin (as PwmOut) and that'd be it. SPI might be special though.

If you see that that does not work, you can use the DestructableSPI class.

DestructableSPI spi(D8, D9, /* etc */);

// when you want to switch
spi.free();
PwmOut pwm(D8);

Accepted Answer

Thank you Jan! I will try this out.

posted by Nicholas Waskewicz 27 Sep 2017