INPUT / OUTPUT Examples

BS1 icon BS2 icon BS2e icon BS2sx icon BS2p icon BS2pe icon BS2px icon

Syntax: INPUT, OUTPUT

 

 

 

' INPUT_OUTPUT.BS1
' This program demonstrates how the input/output direction of a pin is
' determined by the corresponding bit of DIRS. It also shows that the
' state of the pin itself (as reflected by the corresponding bit of PINS)
' is determined by the outside world when the pin is an input, and by the
' corresponding bit of PINS when it's an output. To set up the demo,
' connect a 10k resistor from +5V to P7 on the BASIC Stamp. The resistor
' to +5V puts a high (1) on the pin when it's an input. The BASIC Stamp
' can override this state by writing a low (0) to bit 7 of OUTS and
' changing the pin to output.

' {$STAMP BS1}
' {$PBASIC 1.0}


Main:
  INPUT 7                               ' Make P7 an input
  DEBUG "State of P7: ", #PIN7, CR

  PIN7 = 0                              ' Write 0 to output latch
  DEBUG "After 0 written to OUT7: "
  DEBUG #PIN7, CR

  OUTPUT 7                              ' Make P7 an output
  DEBUG "After P7 changed to output: "
  DEBUG #PIN7
  END

 

NOTE: The example below is written for the BS2 and will run on any of the BS2-family modules. Modify the $STAMP directive (as required) before downloading to the BS2e, BS2sx, BS2p, BS2pe, or BS2px.

' INPUT_OUTPUT.BS2
' This program demonstrates how the input/output direction of a pin is
' determined by the corresponding bit of DIRS. It also shows that the
' state of the pin itself (as reflected by the corresponding bit of PINS)
' is determined by the outside world when the pin is an input, and by the
' corresponding bit of PINS when it's an output. To set up the demo,
' connect a 10k resistor from +5V to P7 on the BASIC Stamp. The resistor
' to +5V puts a high (1) on the pin when it's an input. The BASIC Stamp
' can override this state by writing a low (0) to bit 7 of OUTS and
' changing the pin to output.

' {$STAMP BS2}
' {$PBASIC 2.5}


Main:
  INPUT 7                               ' Make P7 an input
  DEBUG "State of P7: ",
        BIN1 IN7, CR

  OUT7 = 0                              ' Write 0 to output latch
  DEBUG "After 0 written to OUT7: ",
        BIN1 IN7, CR

  OUTPUT 7                              ' Make P7 an output
  DEBUG "After P7 changed to output: ",
        BIN1 IN7
  END

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012