Shop OBEX P1 Docs P2 Docs Learn Events
Ir Remote Control Problems — Parallax Forums

Ir Remote Control Problems

Spartan001Spartan001 Posts: 8
edited 2010-07-08 02:31 in BASIC Stamp
I have a led wired to pin 3 on my Bs2 when I push 1 on my Ir remote the led turns on yet when I push 3 the led does not turn off. Any Ideas?

'
[noparse][[/noparse] Title ]
' Ir Remote Application - IrRemoteButtonDisplay.bs2

' Process incoming SONY remote signals and display the corresponding button
' in the Debug Terminal.

' {$STAMP BS2} ' BS2, 2sx, 2e, 2p, or 2pe
' {$PBASIC 2.5}

'
[noparse][[/noparse] Revision History ]

' V1.0 - Supports most SONY TV and VCR control buttons.
' Supports BASIC Stamp 2, 2SX, 2e, 2p, and 2pe modules.

'
[noparse][[/noparse] I/O Definitions ]

' SONY TV IR remote declaration - input receives from IR detector

IrDet PIN 9
value VAR WORD ' I/O pin to IR detector output

'
[noparse][[/noparse] Constants ]

' Pulse duration constants for SONY remote.

#SELECT $STAMP
#CASE BS2, BS2E, BS2PE ' PULSE durations
ThresholdStart CON 1000 ' Message rest vs. data rest
ThresholdEdge CON 300 ' Binary 1 vs. 0 for RCTIME
OverStart CON 1125 ' Start pulse max
UnderStart CON 675 ' Start pulse min
#CASE BS2P, BS2SX
ThresholdStart CON 2400 ' Binary 1 vs. start pulse
ThresholdPulse CON 500 * 5 / 2 ' Binary 1 vs. 0 for PULSIN
#CASE #ELSE
#ERROR This BASIC Stamp NOT supported.
#ENDSELECT

' SONY TV IR remote constants for non-keypad buttons

Enter CON 11
ChUp CON 16
ChDn CON 17
VolUp CON 18
VolDn CON 19
Mute CON 20
Power CON 21
TvLast CON 59 ' AKA PREV CH

' 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

'
[noparse][[/noparse] Variables ]

' SONY TV IR remote variables

irPulse VAR WORD ' Stores pulse widths
remotecode VAR BYTE ' Stores remote code

'
[noparse][[/noparse] Initialization ]

DEBUG "Press/release remote buttons..."

'
[noparse][[/noparse] Main Routine ]

' Replace this button testing DO...LOOP with your own code.

DO ' Main DO...LOOP
DO
DEBUG CR, CR, "Type value from", CR, "0 to 65535,", CR, "then press ENTER", CR, CR
value = 0
remotecode = 0
DO
value = value * 10 + remotecode
DO
GOSUB Get_Ir_Remote_Code
IF (remotecode > 9) AND (remotecode <> Enter) THEN
DEBUG "Use digit keys or ENTER", CR
PAUSE 300
ELSE
DEBUG "You pressed: "
IF remotecode = Enter THEN
DEBUG "Enter", CR
ELSE
DEBUG DEC remotecode, CR
ENDIF
PAUSE 300
ENDIF
IF value = 1 THEN
HIGH 3

IF value = 3 THEN
LOW 3

ENDIF
ENDIF
LOOP UNTIL (remotecode < 10) OR (remotecode = Enter)
LOOP UNTIL (remotecode = Enter)
DEBUG ? value, CR, "Ready for next value...", CR
LOOP
LOOP

' Repeat main DO...LOOP

'
[noparse][[/noparse] 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
' Wait for resting state between messages to end.
DO
RCTIME IrDet, 1, irPulse
LOOP UNTIL irPulse > ThresholdStart
' Measure start pulse. If out of range, then retry at
' Get_Ir_Remote_Code label.
RCTIME 9, 0, irPulse
IF irPulse > OverStart OR irPulse < UnderStart THEN Get_Ir_Remote_Code
' Get data bit pulses.
RCTIME IrDet, 0, irPulse
IF irPulse > ThresholdEdge 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

Comments

  • ercoerco Posts: 20,256
    edited 2010-07-06 04:50
    Stock readIR routine, right? Lots of code to sift through. Typos could be in there...

    Not sure how you are expecting the variable value to be different than remotecode?

    Try this:

    DEBUG dec value' just see what value is

    IF remotecode = 1 THEN HIGH 3' changed from 'value'

    IF remotecode = 3 THEN LOW 3' changed from 'value'

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • legoman132legoman132 Posts: 87
    edited 2010-07-08 02:31
    It looks to me like:
    IF value = 1 THEN
    HIGH 3
    
    IF value = 3 THEN
    LOW 3
    
    ENDIF
    



    should be:
    IF value = 1 THEN
    HIGH 3
    
    ELSEIF value = 3 THEN
    LOW 3
    
    ENDIF
    



    or:

    IF value = 1 THEN
    HIGH 3
    
    ENDIF
    IF value = 3 THEN
    LOW 3
    
    ENDIF
    
Sign In or Register to comment.