Shop OBEX P1 Docs P2 Docs Learn Events
Changing pin directions mid program — Parallax Forums

Changing pin directions mid program

agentileagentile Posts: 101
edited 2006-03-07 16:44 in BASIC Stamp
Hello,
·· I have a program which requires that a single pin is·configured as an input for part of the program and as an· output for another part of the program.· Using INX and OUTX requires that I initialize my pins with DIRX.· Can I re-initialize pins during the program?· Example:· with the following code work to read and write from the same pin?

DIR1=0
bit_in = IN1
DIR1=1
OUT1=bit_out

thanks,
agentile

Comments

  • Tom WalkerTom Walker Posts: 509
    edited 2006-03-07 14:37
    Yes, you can change a pin's direction at any time. This does increase your responsibility to ensure that your circuitry cannot do "bad" things, such as inadvertently providing a direct short to ground of a "hot" line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • agentileagentile Posts: 101
    edited 2006-03-07 14:42
    Thanks for the help.
  • Charlie JohnsonCharlie Johnson Posts: 147
    edited 2006-03-07 15:52
    Look up the REVERSE command in PBasic 2.5
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-07 16:44
    You can in fact change mid-program; hence the INPUT, OUTPUT,·and REVERSE keywords.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.