' SONY VCR IR remote constants
' IMPORTANT: Before you can make use of these constants, you must
' also follow the universal remote instructions to set your remote
' to control a SONY VCR. Not all remote codes work, so you may have to
' test several.
VcrStop CON 24
VcrPause CON 25
VcrPlay CON 26
VcrRewind CON 27
VcrFastForward CON 28
VcrRecord CON 29
' Function keys
FnSleep CON 54
FnMenu CON 96
' -----[ Variables ]-------------------------------------------------------
' SONY TV IR remote variables
irPulse VAR Word ' Stores pulse widths
remoteCode VAR Byte ' Stores remote code
' -----[ Initialization ]--------------------------------------------------
DEBUG "Press/release remote buttons..."
' -----[ Main Routine ]----------------------------------------------------
' Replace this button testing DO...LOOP with your own code.
DO
GOSUB Get_Ir_Remote_Code
SELECT remoteCode
CASE 2, ChUp ' Forward
PULSOUT 13, 850
PULSOUT 12, 650
CASE 4, VolDn ' Rotate Left
PULSOUT 13, 650
PULSOUT 12, 650
CASE 6, VolUp ' Rotate Right
PULSOUT 13, 850
PULSOUT 12, 850
CASE 8, ChDn ' Backward
PULSOUT 13, 650
PULSOUT 12, 850
CASE 1 ' Pivot Fwd-left
PULSOUT 13, 750
PULSOUT 12, 650
CASE 3 ' Pivot Fwd-right
PULSOUT 13, 850
PULSOUT 12, 750
CASE 7 ' Pivot back-left
PULSOUT 13, 750
PULSOUT 12, 850
CASE 9 ' Pivot back-right
PULSOUT 13, 650
PULSOUT 12, 750
CASE ELSE ' Hold position
PULSOUT 13, 750
PULSOUT 12, 750
ENDSELECT
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
#SELECT $stamp
#CASE BS2, BS2E, BS2PE
DO ' Wait for end of resting state.
RCTIME IrDet, 1, irPulse
LOOP UNTIL irPulse > ThresholdStart
PULSIN IrDet, 0, irPulse ' Get data pulses.
IF irPulse > ThresholdPulse THEN remoteCode.BIT0 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > ThresholdEdge THEN remoteCode.BIT1 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > ThresholdEdge THEN remoteCode.BIT2 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > ThresholdEdge THEN remoteCode.BIT3 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > ThresholdEdge THEN remoteCode.BIT4 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > ThresholdEdge THEN remoteCode.BIT5 = 1
RCTIME IrDet, 0, irPulse
IF irPulse > ThresholdEdge THEN remoteCode.BIT6 = 1
#CASE BS2SX, BS2P
DO ' Wait for start pulse.
PULSIN IrDet, 0, irPulse
LOOP UNTIL irPulse > ThresholdStart
PULSIN IrDet, 0, irPulse ' Get data pulses.
IF irPulse > ThresholdPulse THEN remoteCode.BIT0 = 1
PULSIN IrDet, 0, irPulse
IF irPulse > ThresholdPulse THEN remoteCode.BIT1 = 1
PULSIN IrDet, 0, irPulse
IF irPulse > ThresholdPulse THEN remoteCode.BIT2 = 1
PULSIN IrDet, 0, irPulse
IF irPulse > ThresholdPulse THEN remoteCode.BIT3 = 1
PULSIN IrDet, 0, irPulse
IF irPulse > ThresholdPulse THEN remoteCode.BIT4 = 1
PULSIN IrDet, 0, irPulse
IF irPulse > ThresholdPulse THEN remoteCode.BIT5 = 1
PULSIN IrDet, 0, irPulse
IF irPulse > ThresholdPulse THEN remoteCode.BIT6 = 1
#CASE #ELSE
#ERROR "BASIC Stamp version not supported by this program."
#ENDSELECT
' Map digit keys to actual values.
IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
IF (remoteCode = 10) THEN remoteCode = 0
RETURN