Shop OBEX P1 Docs P2 Docs Learn Events
Tx - Rx with 912MHz — Parallax Forums

Tx - Rx with 912MHz

shmowshmow Posts: 109
edited 2008-02-14 13:17 in BASIC Stamp
 ' {$STAMP BS2}
 ' {$PBASIC 2.5}
 'transmitter code:  - LED (pin 3) is illuminated when button (pin 2 - momentary) is pressed
 '                     and Tx sends value of 1011 with the "XYZ" precursor
Btn             PIN     2
btnWrk          VAR     Byte
LEDpinOne       CON     3
Main:
  BUTTON Btn, 0, 255, 0, btnWrk, 1, Did_Press
  LOW LEDpinOne
  Did_Press:
  IF btn = 0 THEN
    HIGH LEDpinOne
    SEROUT 0, 84, [noparse][[/noparse] "XYZ", DEC 1011 ]
    PAUSE 10
  ENDIF
GOTO Main
 
 
 
 
 ' {$STAMP BS2}
 ' {$PBASIC 2.5}
 'receiver code:  - pin 1 waits for precursor - "XYZ" to assign incoming value - 1011.
 '                - incoming value is assigned to variable serData
 '                - first conditional sets pin 15 high if serData equal 1011 - illumiates LED
 '                - third conditional should "clear" contents of variable serData - with
 '                  debug confirmation
 '                - second conditional sets pin 15 low when variable serData is "cleared"
LEDpin    CON  15
SerData VAR Word
Main:
  SERIN 1, 84, [noparse][[/noparse]WAIT("XYZ"), DEC serData]
  IF serData = 1011 THEN
    HIGH LEDpin
    DEBUG DEC serData, CR
  ENDIF
  IF serData = 0 THEN
    LOW LEDpin
  ENDIF
  IF serData = 1011 THEN
    PAUSE 1000
    serData = 0
    DEBUG DEC serData, CR
  ENDIF
GOTO Main

I've two BOEs each with a transceiver.
One board sends a value when a momentary button is pressed, and the other board turns on an LED when it receives a specific value.

The problem is the LED (on the second board) stays on when the program should turn it off as the valure is "cleared".
I'm not sure why the LED doesn't turn off.··
Any advice?

Thanks,
Johnny Canuck

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-02-13 03:09
    Main:
      SERIN 1, 84, [noparse][[/noparse]WAIT("XYZ"), DEC serData]
      IF serData = 1011 THEN
        HIGH LEDpin
        DEBUG DEC serData, CR
      ENDIF
      IF serData = 0 THEN
        LOW LEDpin
      ENDIF
      IF serData = 1011 THEN
        PAUSE 1000
        serData = 0
        [color=red]LOW LEDpin[/color]
        DEBUG DEC serData, CR
      ENDIF
    GOTO Main
    
  • shmowshmow Posts: 109
    edited 2008-02-13 13:41
    PJ - thanks for the help.

    Wouldn't the second conditional have switched off the LED?

    Shmow
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-02-14 03:15
    ·
     1) Main:
     2)  SERIN 1, 84, [noparse][[/noparse]WAIT("XYZ"), DEC serData]
     3)  IF serData = 1011 THEN    [color=green]' 1st conditional[/color]
     4)    HIGH LEDpin
     5)    DEBUG DEC serData, CR
     6)  ENDIF
     7)  IF serData = 0 THEN       [color=green]' 2nd conditional[/color]
     8)    LOW LEDpin
     9)  ENDIF
    10)  IF serData = 1011 THEN    [color=green]' 3rd conditional[/color]
    11)    PAUSE 1000
    12)    serData = 0            
    13)    [color=red]LOW LEDpin       [/color]
    14)    DEBUG DEC serData, CR
    15)  ENDIF
    16) GOTO Main
    
    

    The "second conditional"·is line 7 (yes?):
    IF serData = 0 THEN LOW LEDpin -- Therefore, if serData is NOT 0 then the THEN LOW LEDpin will not execute.

    IF serData = 1011·in line 3 (that condition is met)·then it would pause for 1 sec, but no matter what value serData, it's made to = 0 in line 12 and the LOW LEDpin in line 13, which I'd added,·executes regardless the value of serData.
  • shmowshmow Posts: 109
    edited 2008-02-14 13:17
    Thanks PJ - for your help.

    Regards,

    Shmow
Sign In or Register to comment.