Shop OBEX P1 Docs P2 Docs Learn Events
Ir Remote Parts kit — Parallax Forums

Ir Remote Parts kit

Colin MennegaColin Mennega Posts: 4
edited 2015-01-04 16:08 in Accessories
Hi,

I am having a problem with programing the infrared remote parts kit for my boe bot
I am working with Bs2 programing code, and the board of education Rev D.
I wrote out and tested this code with the intention of making my boe bot drive forward when the 2 key is pressed :
' {$STAMP BS2}
' {$PBASIC 2.5}

IrDet PIN 9



Enter CON 11
ChUp CON 16
ChDn CON 17
VolUp CON 18
VolDn CON 19
Mute CON 20
Power CON 21
PrevCh CON 59


irPulse VAR Word
remoteCode VAR Byte

DO
GOSUB Get_Ir_Remote_Code
SELECT remoteCode
CASE 2
PULSOUT 13, 650
PULSOUT 12, 850


ENDSELECT

LOOP

Get_Ir_Remote_Code:
remoteCode = 0


DO
RCTIME IrDet, 1, irPulse
LOOP UNTIL irPulse > 1000

RCTIME 9, 0, irPulse
IF irPulse > 1125 OR irPulse < 675 THEN GOTO Get_Ir_Remote_Code

RCTIME IrDet, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT0 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT1 = 1
RCTIME IrDet, 0, irPulse ' etc
IF irPulse > 300 THEN remoteCode.BIT2 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT3 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT4 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT5 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT6 = 1


IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
IF (remoteCode = 10) THEN remoteCode = 0
RETURN



It worked out very well, so i decided to change this:
CASE 2
PULSOUT 13, 650
PULSOUT 12, 850

To this:


CASE 2
DO
PULSOUT 13, 650
PULSOUT 12, 850
LOOP UNTIL (remoteCode = 1)

In the hope that when the 2 key is pressed and released the boe bot will keep driving forward until the 1 key is pressed. However when the 2 key is pressed the boe bot keeps driving forward regardless of the 1 key.
I tried every key on the remote just to make sure, but nothing happens.
What am I doing wrong?
Thanks!
By the way please tell me if Basic Stamp is a better category for this topic.

Comments

  • GenetixGenetix Posts: 1,754
    edited 2015-01-04 13:49
    Hello Colin,

    Your new inner loop bypasses the Get_Ir_Remote_Code subroutine which is the part of your program that changes RemoteCode.
    Since RemoteCode can never change your program gets stuck in an infinite loop.

    This post would be best in Learn or Robotics since it involves the Boe-Bot.
  • Colin MennegaColin Mennega Posts: 4
    edited 2015-01-04 14:07
    Thank you for your help!
    How do I change the code to make it work?
    Sorry, I am very new at programming.
    Thank you again!
    Colin
  • GenetixGenetix Posts: 1,754
    edited 2015-01-04 15:09
    I don't know what you are trying to do but the Boe-Bot will only move forward when the 2 button is pressed because of the way you wrote the original program.
    Those 2 PULSOUT commands that move the Boe-Bot forward will only run when the IR Code is 2.
    Any other IR code will do nothing since your program doesn't say what to do with them.

    You should learn how to ident your program to make it easier to read.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    IrDet     PIN     9
    
    
    Enter   CON       11
    ChUp    CON       16
    ChDn    CON       17
    VolUp   CON       18
    VolDn   CON       19
    Mute    CON       20
    Power   CON       21
    PrevCh  CON       59
    
    
    irPulse VAR Word
    remoteCode VAR Byte
    
    DO
      GOSUB Get_Ir_Remote_Code
    
      SELECT remoteCode
        CASE 2
          PULSOUT 13, 650
          PULSOUT 12, 850
      ENDSELECT
    
    LOOP
    
    
    Get_Ir_Remote_Code:
      remoteCode = 0
    
      DO
        RCTIME IrDet, 1, irPulse
      LOOP UNTIL (irPulse > 1000)
    
      RCTIME 9, 0, irPulse
      IF (irPulse > 1125) OR (irPulse < 675) THEN GOTO Get_Ir_Remote_Code
    
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT0 = 1
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT1 = 1
      RCTIME IrDet, 0, irPulse			' etc
      IF (irPulse > 300) THEN remoteCode.BIT2 = 1
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT3 = 1
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT4 = 1
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT5 = 1
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT6 = 1
    
    
      IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
      IF (remoteCode = 10) THEN remoteCode = 0
    
      RETURN
    
  • Colin MennegaColin Mennega Posts: 4
    edited 2015-01-04 15:23
    I am trying to make the robot to drive forward only when the 2 key is pressed,
    keep driving forward regardless of whether the 2 key is released,
    then stop driving forward only when the 1 key is pressed.
    Can that be done?
    I am willing to change or rewrite my program, but I don't know what to change, or how to change it.
    Thank you again,
    Colin
  • GenetixGenetix Posts: 1,754
    edited 2015-01-04 15:57
    Try this. I commented it so it's easier to understand.
    ' {$STAMP BS2}		' Tells compiler to use BS2
    ' {$PBASIC 2.5}		' Tells compiler to use PBASIC 2.5
    
    ' I/O Pin Declaration
    IrDet PIN 9		' IR receiver/detector
    
    ' Constant Declarations
    Enter CON 11
    ChUp CON 16
    ChDn CON 17
    VolUp CON 18
    VolDn CON 19
    Mute CON 20
    Power CON 21
    PrevCh CON 59
    
    ' Variable Declarations
    irPulse VAR Word	' Length of IR pulse
    remoteCode VAR Byte	' Remote Code received
    button2Pressed VAR Bit	' Added - Flag Bit for Button 2 being pressed, remains on until Button 1 is pressed
    
    
    ' Initialization
    button2Pressed = 0	' Added - Initialize Flag to 0 (Off)
    
    
    ' Main Loop
    DO				' Start of Main Loop - Loops Forever
    
      GOSUB Get_Ir_Remote_Code	' Go to Subroutine
    
      SELECT remoteCode		' Start of SELECT...CASE
        CASE 1			' Added (remoteCode = 1)
          button2Pressed = 0	' Added - Clear Flag (Off)
        CASE 2			' RemoteCode = 2
          button2Pressed = 1	' Added	- Set Flag (On)
      ENDSELECT			' End of SELECT...CASE
    
      IF (button2Pressed = 1) THEN	' Added - Check if Flag is On
          PULSOUT 13, 650		' Moved from CASE 2 to here (Move forward)
          PULSOUT 12, 850		' Moved from CASE 2 to here
      ENDIF				' Added (Needed since more than one statement follow IF...THEN)
    
    LOOP				' End of Main Loop
    
    
    ' Subroutine
    Get_Ir_Remote_Code:
      remoteCode = 0	' Initialize to 0
    
    
      DO				' Loop
        RCTIME IrDet, 1, irPulse
      LOOP UNTIL (irPulse > 1000)	' End of Loop - Wait for a long pulse
    
      RCTIME 9, 0, irPulse
      IF (irPulse > 1125) OR (irPulse < 675) THEN GOTO Get_Ir_Remote_Code	' Try again if pulse is too big or small
    
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT0 = 1	' Set Bit 0 - Value of 1
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT1 = 1	' Set Bit 1 - Value of 2
      RCTIME IrDet, 0, irPulse 			' etc
      IF (irPulse > 300) THEN remoteCode.BIT2 = 1	' Set Bit 2 - Value of 4
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT3 = 1	' Set Bit 3 - Value of 8
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT4 = 1	' Set Bit 4 - Value of 16
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT5 = 1	' Set Bit 5 - Value of 32
      RCTIME IrDet, 0, irPulse
      IF (irPulse > 300) THEN remoteCode.BIT6 = 1	' Set Bit 6 - Value of 64
    
    
      IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
      IF (remoteCode = 10) THEN remoteCode = 0
     
      RETURN
    
  • Colin MennegaColin Mennega Posts: 4
    edited 2015-01-04 16:08
    Thank you very much for your help!
Sign In or Register to comment.