pindir( pinname , pintype )

Set Pin Direction

Use: pindir( pinname, pintype )
Description: Sets the direction of a pin. eg. to be an input or output.
Parameters: pinname Name of the input pin, This can be in the form Px_y. Where x is the port number, which can be 1 or 2, and y is the bit number which is 0 to 7. (e.g. P2_3)
 pintype Specifies the pin type. This must be one of the following values:
OUT : sets the pin to be an output
IN : sets the pin to be an input (a floating input)
INPD : sets the pin to be an input, with a pulldown resistor
INPU : sets the pin to be an input, with a pullup resistor
PULSEOUT : sets the pin to be used as a timer output 
Returns None
Related:  inp( ),  out( ),


The pindir( ) command is used to set the direction of a pin so that it can be used as an input or output or some other function eg. a pulse output.

When the pin is set to any of the input pintypes e.g.  pindir( pin, IN)  use the inp( ) command to read the value of the pin

When the pin is set to an output pintype e.g. pindir( pin, OUT) use the out( ) command to set the value on the pin.

Note when the mpy program starts, all pins are automatically set to inputs with pulldown resistor pindir( pin, INPD). This means there are no floating input pins.

Example:

pindir(P1_0, OUT) # Set port P1_0 as an output (Launchpad red led)
pindir(P1_3, INPU) # Set port P1_3 as an input (with pullup resistor)
while 1: # do forever
    switch_input = inp(P1_3) # read the input from pin P1_3
    out(P1_0, switch_input) # set the output pin P1_0 (red led)

This example uses input pin p1_3. This is connected to switch S2 on the Launchpad board. When the switch is pressed the red LED on pin P1_0 will be switched off.