ir remote control code help
I have a awesome bot that uses a h-bridge that I made myself that consits or relays and a couple of transistors. Everything is perfect except for two things. I am using a ir remote control from a sony tv, so it has a quite limited range. When the bot gets out of range then ir does not receive the brake signal from the remote. Also when it loses the signal then it just keeps going eventually hitting a wall. I would use a contact sensor of some sort but it goes way to fast and is too heavy to stop from top speed to zero in under the distance of a foot. I also would use a ping sensor, but I am really tight on money, due to me spending it all on an 8800gt and q6600. I have no idea how to make the bs2 sense, that there was no signal for 100 ms, and therefor stop. I have the code here to make your lives esiaer. 
makelow is what makes the bot stop.

' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word
irPulse VAR Word
remoteCode VAR Byte
t VAR Word
b VAR Word
LOW 12
LOW 13
LOW 14
LOW 15
PAUSE 100
start:
DO
GOSUB remote
GOSUB move
remoteCode = 15
LOOP
remote: ' Main DO...LOOP
Get_Pulses: ' Label to restart message check
remoteCode = 0 ' Clear previous remoteCode
' Wait for resting state between messages to end.
DO
RCTIME 9, 1, irPulse
LOOP UNTIL irPulse > 1000
' Measure start pulse. If out of range, then retry at Get_Pulses label.
RCTIME 9, 0, irPulse
IF irPulse > 1125 OR irPulse < 675 THEN GOTO Get_Pulses
' Get Data bit pulses.
RCTIME 9, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT0 = 1
RCTIME 9, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT1 = 1
RCTIME 9, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT2 = 1
RCTIME 9, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT3 = 1
RCTIME 9, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT4 = 1
RCTIME 9, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT5 = 1
RCTIME 9, 0, irPulse
IF irPulse > 300 THEN remoteCode.BIT6 = 1
' Map digit keys to actual values.
IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
IF (remoteCode = 10) THEN remoteCode = 0
DEBUG CLS, ? remoteCode
RETURN
backwardall:
HIGH 12
HIGH 13
HIGH 14
LOW 15
RETURN
forwardall:
HIGH 12
LOW 13
HIGH 15
HIGH 14
RETURN
goright:
HIGH 12
HIGH 13
LOW 15
LOW 14
PAUSE 100
RETURN
goleft:
HIGH 12
LOW 13
HIGH 15
LOW 14
PAUSE 100
RETURN
makelow: ' brake
LOW 12
LOW 13
LOW 14
LOW 15
RETURN
light:
HIGH 0
PAUSE 100
RCTIME 0, 1, time
DEBUG HOME, " time = " ,DEC5 time
RETURN
move:
GOSUB makelow
IF remoteCode = 117 THEN
GOSUB backwardall
ENDIF
IF remoteCode = 116 THEN
GOSUB forwardall
ENDIF
IF remoteCode = 52 THEN
GOSUB goleft
ENDIF
IF remoteCode = 51 THEN
GOSUB goright
ENDIF
IF remoteCode = 101 THEN
GOSUB makelow
ENDIF
PAUSE 100
RETURN
makelow is what makes the bot stop.

Comments