Shop OBEX P1 Docs P2 Docs Learn Events
IR remote program help — Parallax Forums

IR remote program help

AnnoyingAnnoying Posts: 50
edited 2010-03-04 11:04 in Accessories
so I want to use the IR remote to turn my robot on and off (If button 1 is pressed, start program, if button 2 is pressed, stop), and this basic program that I wrote doesn't work. I tried a lot of debug statements but I can't figure it out. It's just very inconsistent and so if you could find the flaw in logic I'd appreciate it!



'{$STAMP BS2}
'{$PBASIC 2.5}
time VAR Word(2) ' SONY TV remote variables.

Start:
·· DEBUG "Start"


·DO ' Wait for rest between messages.
RCTIME 12, 1, time(0)
LOOP UNTIL time(0) > 1000

PULSIN 12, 0, time(0) ' Measure/store data pulses.
PULSIN 12, 0, time(1)

IF (time(1) < 500) AND (time(0) < 500) THEN··· 'If Button 1 is pressed start program
GOTO Main
ENDIF

GOTO Start


Main:

DEBUG "Main"


PULSIN 12, 0, time(0) ' Measure/store data pulses.
PULSIN 12, 0, time(1)


IF (time(1) < 500) AND (time(0) > 500) THEN···· ·'If button 2 is pressed stop program
GOTO Start
ENDIF


GOTO Main



·

Comments

  • PrettybirdPrettybird Posts: 269
    edited 2010-02-23 22:38
    I used theSony IR program from Parallax and it works fine if that is any help. Look up on their IR sensors I think
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-02-24 02:04
    · Try this and see if this works
    '{$STAMP BS2}
    '{$PBASIC 2.5}
     
     
    time VAR Word(2)                                        ' SONY TV remote variables.
     
     
    Pick_One:
       DEBUG "Start"
     
    DO
      
     DO                                                    ' Wait for rest between messages.
    RCTIME 12, 1, time(0)
    LOOP UNTIL time(0) > 1000
     
    PULSIN 12, 0, time(0)                                 ' Measure/store data pulses.
    PULSIN 12, 0, time(1)
     
     
    IF (time(1) < 500) AND (time(0) < 500) THEN           'If Button 1 is pressed start program
    GOSUB Start
    ELSE
    IF (time(1) < 500) AND (time(0) > 500) THEN           'If button 2 is pressed stop program
    GOSUB End_P
    
    ENDIF
    ENDIF
     
    LOOP
    
    Start:
    DEBUG "START"
    PAUSE 1000
    GOSUB Pick_One
    RETURN
     
    End_P:
    DEBUG "Stop"
    PAUSE 1000
    GOSUB Pick_One
    RETURN
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 2/24/2010 2:28:19 AM GMT
  • AnnoyingAnnoying Posts: 50
    edited 2010-02-24 05:03
    thanks...unfortunately it still doesn't do quite what I want...I need the condition "if button 2 is pressed,end the program" to be within the main start program because I want to be able to turn the robot off while it's moving. If I press the button 2 to stop it, it should just go back to the beginning of the program where it checks if the on button is pressed. sounds simple enough but doesn't work for me...ahhhhhh!
  • ercoerco Posts: 20,255
    edited 2010-03-01 17:55
    The Parallax readIR program is pretty bulletproof. First, make sure that yours is functioning properly. It takes a certain amount of time to execute, you CANNOT insert DEBUG statements inside its main loop, that will mess you up. You can debug the code detected after the routine executes. Also, you need to integrate that routine properly with your program so that you loop through the readIR portion regularly. I use readIR as a subroutine and GOSUB to it inside my main program loop. Again, it takes a short amount of time to execute before control RETURNs to your main program. Usually that's not a problem.

    My most recent encoder project was very timing-critical, and I could not wait for the whole readIR routine to execute, yet I needed to exit my main program by an IR remote signal. In that case, I had a single, fast-executing IF statement inside my main program loop that looked at the IR sensor output. Any LOW signal (IF IN0=0 THEN...) would exit the main loop, so any keypress on the remote triggered the exit routine. That may or may not work in your case.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • AnnoyingAnnoying Posts: 50
    edited 2010-03-04 08:12
    so what is the parallax readIR program? thanks!
  • Oper8r AlOper8r Al Posts: 98
    edited 2010-03-04 11:04
    Here is a link to the parallax Infrared Remote AppKit pdf. It may help you solve your problem. Near the end they discuss controlling a boe-bot with IR.

    www.parallax.com/dl/docs/prod/compshop/IRremoteAppKit.pdf
Sign In or Register to comment.