trouble with xbee code
gennarobasso81
Posts: 84
hello all,
I am having trouble with some code for an xbee. overview of project is i have two bs2's connected to xbees, I have one bs2/xbee with two pushbuttons the other with two different colored led's. I am trying to get it so one pushbutton will control one color and the other pushbotton the other color.
problem i am having:
regardless of what button is pushed the lights go on in a pattern. first the green, then the red. If i hit Pushbutton one 5 time it will go green, red, green......and so on. it i hit any combination of the two buttons it still repeats the pattern of green, red, green, red, green,...and so on
transmitting code
receiving code
I am having trouble with some code for an xbee. overview of project is i have two bs2's connected to xbees, I have one bs2/xbee with two pushbuttons the other with two different colored led's. I am trying to get it so one pushbutton will control one color and the other pushbotton the other color.
problem i am having:
regardless of what button is pushed the lights go on in a pattern. first the green, then the red. If i hit Pushbutton one 5 time it will go green, red, green......and so on. it i hit any combination of the two buttons it still repeats the pattern of green, red, green, red, green,...and so on
transmitting code
' {$STAMP BS2} ' {$PBASIC 2.5} '----------------[Initialize]--------------------------- PAUSE 5 SEROUT 2, 84, [22,12] SEROUT 2, 84,50, [22,17, "Hello", 13, "Geno"] PAUSE 1000 SEROUT 2, 84, [22,12] PAUSE 5 '---------------[Variables]----------------------------- LR VAR Word UD VAR Word btn1wrk VAR Byte btn2wrk VAR Byte Led VAR Bit Led1 VAR Bit '---------------[Constants]----------------------------- BUTTON btn1, 1, 0, 0, btn1Wrk,0, No_Press BUTTON btn2, 1, 0, 0, btn2Wrk,0, No_Press Btn1 PIN 6 Btn2 PIN 7 Tx PIN 14 ' XBee DIN Rx PIN 15 ' XBee DOUT stickUD CON 25 stickLD CON 25 '-------------------------[Main]--------------------------- Main: HIGH 13 PAUSE 2 RCTIME 13, 1, UD HIGH 12 PAUSE 2 RCTIME 12, 1, LR DEBUG HOME, "UD =", DEC UD, CLREOL, CR, "LR = ", DEC LR, CLREOL IF UD > stickUD + 2 THEN GOSUB Forward IF UD < stickUD - 2 THEN GOSUB Backwards IF UD = stickUD THEN GOSUB Clear IF LR > stickLD + 2 THEN GOSUB Right IF LR < stickLD - 2 THEN GOSUB Left IF LR = stickLD THEN GOSUB Clear IF btn1 =1 THEN DEBUG CR, "Button 1 pushed" GOSUB Left_Turn DEBUG CLS ENDIF IF btn2 = 1 THEN DEBUG CR, "Button 2 pushed" GOSUB Right_Turn DEBUG CLS ENDIF No_Press: GOTO main GOTO main '-------------------------[Sub Routine]----------------------- Forward: SEROUT 2,84, 20, [17, 128, "Forward"] PAUSE 200 RETURN Backwards: SEROUT 2, 84, 20, [17, 128, "Backwards"] PAUSE 200 RETURN Right: SEROUT 2, 84, 20, [17, 148, "Right"] PAUSE 200 RETURN Left: SEROUT 2, 84, 20, [17,148, "left"] PAUSE 200 RETURN Clear: SEROUT 2, 84, [12,17] PAUSE 200 RETURN Left_Turn: IF Btn1 = 1 THEN SEROUT 2, 84, ["Left", 13, "Turn"] SEROUT Tx, 84,[ DEC Led,CR] PAUSE 500 IF Btn1 = 0 THEN SEROUT 2, 84, [12] PAUSE 5 RETURN Right_Turn: IF btn2 = 1 THEN SEROUT 2, 84, ["Right", 13, "Turn"] SEROUT Tx, 84, [DEC Led1,CR] PAUSE 500 IF btn2 = 0 THEN SEROUT 2, 84, [12] PAUSE 5 RETURN
receiving code
' *************************************************** ' Simple_Control_Remote.bs2 ' Receives decimal value to control buzzer and LED ' *************************************************** ' {$STAMP BS2} ' {$PBASIC 2.5} #SELECT $STAMP #CASE BS2, BS2E, BS2PE T9600 CON 84 #CASE BS2SX, BS2P T9600 CON 240 #CASE BS2PX T9600 CON 396 #ENDSELECT ' ***************** Variables, Constants and Pins Baud CON T9600 ' Set Baud rate Rx PIN 15 ' XBee DOUT Tx PIN 14 ' XBee DIN Led PIN 0 Led1 PIN 1 green VAR Byte red VAR Byte ' ***************** Main Loop DO SERIN Rx, Baud, [DEC green] ' Wait for decimal and accept HIGH LED ' Turn on LED PAUSE 1000 LOW LED ' Turn off LED SERIN Rx, Baud, [DEC red] HIGH Led1 PAUSE 1000 LOW Led1 LOOP
Comments
this is one example. It was all i had to show because i didnt save any of the non working codes.
transmit
receive