Shop OBEX P1 Docs P2 Docs Learn Events
2 stamp Need help?? — Parallax Forums

2 stamp Need help??

TomvnTomvn Posts: 103
edited 2008-07-29 16:17 in BASIC Stamp
can anyone help to explain this code or add the comment to it, i want to make some adjustment in this code·use ir sensor to make· Bs2 Stamp to control my Boebot move,
but i still not get thought all this code, two sample code below one for transmitting( Bs2 Stamp)·and one for reciver (Boebot)


'
'File Name: Program Listing 1.6 - Stamp-2-Stamp IR_tx.BS2
'
IR_LED_pin CON 7
IR_freq CON 37500
start_bit CON 1
stop_bit CON 4
bin_0 CON 2
bin_1 CON 3
between_pulses CON 2
counter VAR Nib
IR_message VAR Byte
duration VAR Nib
IR_message = 25
FREQOUT IR_LED_pin,start_bit,IR_freq
PAUSE between_pulses
FOR counter = 0 TO 7
duration = 2 + IR_message.LOWBIT(counter)
FREQOUT IR_LED_pin,duration,IR_freq
PAUSE between_pulses
NEXT
FREQOUT IR_LED_pin,stop_bit,IR_freq
' ****** Reset Stamp to run again *******
STOP


'
'File Name: Program Listing 7 - Stamp-2-Stamp IR_rx.BS2
'
IR_detect_pin CON 8
IR_signal VAR IN8
start_bit CON 500
bin_0 CON 1100
bin_1 CON 1600
stop_bit CON 1900
active_low CON 0
counter VAR Nib
IR_pulse VAR Word
duration VAR Nib
IR_message VAR Byte
LOOP:
IF IR_signal = 1 THEN LOOP
process_message:
PULSIN IR_detect_pin,active_low,IR_pulse
IF IR_pulse > stop_bit THEN display_message
LOOKDOWN IR_pulse, < [noparse][[/noparse]bin_0,bin_1],
IR_message.LOWBIT(counter)
counter = counter + 1
GOTO process_message
display_message:
DEBUG "Message received,", CR
DEBUG "it's ", DEC3 IR_message, CR
IR_message = 0
counter = 0
GOTO LOOP

Thanks.

Post Edited (Tomvn) : 7/25/2008 5:25:30 PM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-07-26 02:12
    Where did you get the listings and what did that source say about them?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • TomvnTomvn Posts: 103
    edited 2008-07-26 04:04
    the sourse not explain at all it say the code for 2 stamp communicate with each other by Ir sensor.
  • FranklinFranklin Posts: 4,747
    edited 2008-07-26 19:37
    Does the code work? Have you loaded and tested it?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • TomvnTomvn Posts: 103
    edited 2008-07-26 23:22
    i am not tested yet, but i just need some adjustment in the code to make the Boebot move around, So can i replace display message subroutine with some movement subroutine ,like when Ir led on IR detector from the Boebot detect it and the servo move...
  • FranklinFranklin Posts: 4,747
    edited 2008-07-26 23:52
    I wouldn't modify code before I knew it worked. How will you know if your changes broke the code or if it didn't work in the first place?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • TomvnTomvn Posts: 103
    edited 2008-07-27 02:17
    that code it from parallax ir manual do you think it work?
  • FranklinFranklin Posts: 4,747
    edited 2008-07-27 03:04
    I don't know but you should try it, then you will know.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • TomvnTomvn Posts: 103
    edited 2008-07-29 16:17
    sorry for my delay
    i just tested and it work well , but i try to modifiel the RX file to make it 3 seperated detector to see 1 IR LEd, 3 Ir detector on boebot but on different direction , each irdetector if see the for samlpe if left see the bot will turn let 30 degree
    so center see the boebot forward to the ir led . but cant make it work , here the sample...
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    'File Name: Program Listing 7 - Stamp-2-Stamp IR_rx.BS2
    '
    IR_detect_left CON 3
    IR_detect_right CON 4
    IR_detect_center CON 5
    IR_signal_5 VAR IN5
    IR_signal_4 VAR IN4
    IR_signal_3 VAR IN3
    start_bit CON 500
    bin_0 CON 1100
    bin_1 CON 1600
    stop_bit CON 1900
    active_low CON 0
    counter VAR Nib
    IR_pulse VAR Word
    duration VAR Nib
    IR_message VAR Byte
    loopi:
    IF IR_signal_3 = 1 THEN loopi
    process_message:
    PULSIN IR_detect_left,active_low,IR_pulse
    IF IR_pulse > stop_bit THEN vacuum ' see vacuum sub start running
    LOOKDOWN IR_pulse, < [noparse][[/noparse]bin_0,bin_1],
    IR_message.LOWBIT(counter)
    counter = counter + 1
    GOTO process_message
    display_message:
    DEBUG "Message received,", CR
    DEBUG "it's ", DEC3 IR_message, CR
    IR_message = 0
    counter = 0
    vacuum:
    FOR ir_message = 1 TO 250
    PULSOUT 14, 650
    NEXT
    RETURN
    stepi:
    IF IR_signal_5 = 1 THEN stepi
    process_message:
    PULSIN IR_detect_center,active_low,IR_pulse

    IF IR_pulse > stop_bit THEN forward ' see forward pulse run forward
    LOOKDOWN IR_pulse, < [noparse][[/noparse]bin_0,bin_1],
    IR_message.LOWBIT(counter)
    counter = counter + 1
    GOTO process_message
    display_message:
    DEBUG "Message received,", CR
    DEBUG "it's ", DEC3 IR_message, CR
    IR_message = 0
    counter = 0
    forward:
    FOR ir_message = 1 TO 200
    PULSOUT 13, 650
    PULSOUT 12, 850
    NEXT
    RETURN
Sign In or Register to comment.