' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[ I/O Definitions ]-------------------------------------------------
' SONY TV IR remote declaration - input received from IR detector
IrDet PIN 12
' -----[ Constants ]-------------------------------------------------------
' SONY TV IR remote constants for non-keypad buttons
Speed VAR Word
Speed = 250
Enter CON 11
ChUp CON 16
ChDn CON 17
VolUp CON 18
VolDn CON 19
Power CON 21
' -----[ Variables ]-------------------------------------------------------
' SONY TV IR remote variables
irPulse VAR Word
remoteCode VAR Byte
SERVO_L CON 13
SERVO_R CON 14
'ECHO CON 2
'INIT CON 3
DEBUGMODE CON 0
STOP_POS CON 765
I VAR Word
DIRA = %0000
DIRB = %1111
DIRC = %1111
DIRD = %1110
' -----[ Main Routine ]----------------------------------------------------
' Replace this DO...LOOP with your own Code.
DO
GOSUB Get_Ir_Remote_Code
DEBUG CLS, "Remote code: ", DEC remoteCode
IF remotecode = ChUp THEN FORWARD
IF remotecode = ChDn THEN BACKWARD
IF remotecode = VolUp THEN left
IF remotecode = VolDn THEN right
IF remotecode = Power THEN STOP1
IF remotecode = 101 THEN Armmoveup
IF remotecode =29 THEN Armmovedown
PAUSE 100
LOOP
' -----[ Subroutine - Get_Ir_Remote_Code ]---------------------------------
' SONY TV IR remote subroutine loads the remote code into the
' remoteCode variable.
Get_Ir_Remote_Code:
remoteCode = 0 ' Clear all bits in remoteCode.
DO ' Wait for rest between messages.
RCTIME IrDet, 1, irPulse
LOOP UNTIL irPulse > 1000
PULSIN IrDet, 0, irPulse ' Measure pulse.
IF irPulse > 500 THEN remoteCode.BIT0 = 1 ' Set (or leave clear) bit-0.
RCTIME IrDet, 0, irPulse ' Measure next pulse.
IF irPulse > 300 THEN remoteCode.BIT1 = 1 ' Set (or leave clear) bit-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
' Adjust remoteCode so that keypad keys correspond to the value
' it stores.
IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
IF (remoteCode = 10) THEN remoteCode = 0
RETURN
FORWARD:
OUTC= %1111
PAUSE 200
RETURN
BACKWARD:
OUTC= %0101
PAUSE 200
RETURN
LEFT:
OUTC= %0111
PAUSE 200
RETURN
RIGHT:
OUTC= %1011
PAUSE 200
RETURN
STOP1:
OUTC= 0
PAUSE 200
RETURN
Armm1:
HIGH 14
PAUSE 200
RETURN
Arms1:
LOW 14
PAUSE 200
RETURN
Armmoveup:
PULSOUT 13 ,750 + Speed ' Servo plug in pin13
PAUSE 20
RETURN
Armmovedown:
PULSOUT 13 ,750 - Speed ' Servo plug in pin13
PAUSE 20
RETURN
Chatboard (0)