Changing a pin's type in a program

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.