Download Print this page

Program Examples - Parallax 32401 Manual

Xbee 5v/3.3v adapter

Advertisement

®
BASIC Stamp

2 Program Examples

The sample code below demonstrates simple communication using two XBee modules interfacing with
two BASIC Stamp 2 microcontrollers.
pushbutton connected to P13 while the second program, XBeeRX_PbLed.bs2 receives the state of the
pushbutton, displays it on the Debug Terminal, and turns on an LED if the button is pressed. Both
programs can be downloaded from the 32401 product page at www.parallax.com.
' {$STAMP BS2}
' {$PBASIC 2.5}
' XBeeTX_PbLed.bs2
' Sends state of an active-high pushbutton connected to P13
TX
PIN
14
DO
SEROUT TX, 84, [BIN IN13, CR]
PAUSE 250
LOOP
' {$STAMP BS2}
' {$PBASIC 2.5}
' XBeeRX_Simple.bs2
' Received state of pushbutton, displays state in Debug Terminal
' and turns on an LED if the button is pressed.
RX
PIN
15
PbState
VAR
Bit
DO
SERIN RX, 84, [BIN PbState]
DEBUG HOME, ? PbState
IF PbState = 1 THEN HIGH 13 ELSE LOW 13
LOOP
Copyright © Parallax Inc.
The first program, XBeeTX_PbLed.bs2 sends the state of a
' XBee DIN pin
' Sends state of pushbutton
' Short pause
' Loop forever
' XBee DOUT pin
' Variable space for pushbutton state
' Receives pushbutton state
' Displays state in Debug Terminal
' LED on if pressed/off if not pressed
' Loop forever
XBee 5V/3.3V Adapter (#32401)
v1.2 7/27/2010 Page 6 of 6

Advertisement

loading