Ir Remote Parts kit
Colin Mennega
Posts: 4
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.
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
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.
How do I change the code to make it work?
Sorry, I am very new at programming.
Thank you again!
Colin
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.
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