Arm Mbed and Pelion Device Management support forum

Changing a pin's type in a program

Hello everyone!

How can one change the “type” of a pin - for example, change the physical pin from DigitalIn to DigitalOut? If I declare a pin one type in a function, can I declare it to be a different type in another function call later?

I want to be able to configure the pins programmatically so I can change them during the execution of the program.

I’m not trying to switch them rapidly or anything, I simply want to be able to change a pin’s type from time to time as needed for my device.

Thanks!

Hello,

In case you need a DigitalIn and a DigitalOut on the same pin the simplest solution is to use a DigitalInOut. But in other situations the solution could be creating and deleting objects dynamically as explained here.

Thank you! For some I’m not receiving notifications from the forum for replies.
The DigitialInOut is exactly what I need. I’ve tested it and it seems to be working.