# INPUT

INPUT / OUTPUT Examples

Syntax: INPUT Pin

## Function

Make the specified pin an input.

- Pin is a variable/constant/expression* (0 - 15) that specifies which I/O pin to set to input mode.

* Note: expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0–7.

## Quick Facts

| BS1 | All BS2 Models
Input Pin Variables | PINS: PIN0 through PIN7 | INS; IN0 through IN15
Related Commands | OUTPUT, REVERSE

## Explanation

There are several ways to make a pin an input. When the BASIC Stamp is reset, all of the pins are inputs. Commands that rely on input pins, like PULSIN and SERIN, automatically change the specified pin to input. Writing 0s to particular bits of the variable DIRS makes the corresponding pins inputs. And then there’s the INPUT command.

When a pin is an input, your program can check its state by reading from the corresponding INS variable (PINS on the BS1). For example:

    Setup:
      INPUT 4

    Hold:
      IF PIN4 = 0 THEN Hold                         ' Stay here until P4 is 1

    Setup:
      INPUT 4

    Hold:
      IF (IN4 = 0) THEN Hold                        ' Stay here until P4 is 1

What happens if your program writes to the OUTS bit (PINS bit on the BS1) of a pin that is set up as an input? The value is stored in OUTS (PINS on the BS1), but has no effect on the outside world. If the pin is changed to output, the last value written to the corresponding OUTS bit (or PINS bit on the BS1) will appear on the pin. The Example program shows how this works.

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012