Shop OBEX P1 Docs P2 Docs Learn Events
Working on a routine to make a remote have functionality like the Button command — Parallax Forums

Working on a routine to make a remote have functionality like the Button command

JohnmarkJohnmark Posts: 10
edited 2010-01-15 18:53 in BASIC Stamp
I am trying to make a IF remote program that acts like the button command. This is for control of a stereo preamp. I want the remote volume control to act like any normal one. A push of less then one second, indexes the digital pot one notch. Holding the control longer will make the digital pot go up one notch every tenth of a second until the key is released.

Before I spend some time doing this, I wonder if someone else has already done this.

Thanks

John

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-01-14 23:32
    Maybe somebody has a software solution.· I'm seeing hardware, but I'll wait till someone offers s/w.
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2010-01-15 00:13
    ·· Psuedo Code:

    ······ DO WHILE IR DECTOR=ACTIVE

    ·········· CHECK FOR PROPER IR PROTOCOL

    ·········· ·DECODE IR·PULSE TRAIN ( volume UP or volume DOWN)

    ····················· IF command =volume UP/DOWN· GOSUB Do_Something

    ········· LOOP



    ········Do-Something:

    ··········· increment or decrement volume accumulator

    ··········· use acumulator value to set volume

    ··········· PAUSE to control command decode frequency

    ··········· wait for IR DETECTOR to become ACTIVE or do someting else (while checking for IR )

    ··········· RETURN



    ··· I have implemented a volume control that worked with a VMusic2 module and used the Sony TV IR protocol.· Don't know if this will help.



    ········
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2010-01-15 00:52
    Maybe a description would better describe it: Initialize the volume variable to its default value. Check periodically for activity on the IR detector; when active, check for the proper protocol and if OK, decode the pulse train. If, for example, the command is VOLUME UP, increment the volume variable and use it to set the digital pot's value. Incorporate some kind of delay (this will control the rate at which commands are processed and acts as a "debounce" to prevent a single command from being interpreted multiple times) . Next, go back to checking the IR detector before doing anything else; if its active, return to the decoding routine. Be sure not to get stuck in any loops while decoding signals- exit the loop if the IR detector goes inactive.
  • JohnmarkJohnmark Posts: 10
    edited 2010-01-15 14:15
    Thanks to all. This will get me started. I am sure I will be back for more help. I'll post code as soon as I have something worth sharing.

    John
  • JohnmarkJohnmark Posts: 10
    edited 2010-01-15 18:53
    Here is what I have so far. It works pretty well. It does bounce occasionally. I used the Boe-Bot IR and Digital pot from What's a Microcontroller as starting points for the code and the circuit. The nice thing is that the circuit works with the DS1666 pot I want to use in my preamp.

    '
    [noparse][[/noparse] Title ]
    ' IR for preamp control
    ' Capture and store button codes sent by a universal remote configured to
    ' control a SONY TV.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    '
    [noparse][[/noparse] I/O Definitions ]
    ' SONY TV IR remote declaration - input received from IR detector
    IrDet PIN 9

    '
    [noparse][[/noparse] Variables ]
    ' SONY TV IR remote variables
    irPulse VAR Word
    remoteCode VAR Byte

    ' Button variables
    counter VAR Byte
    Volume VAR Byte

    '
    [noparse][[/noparse] Main Routine ]
    ' Replace this DO...LOOP with your own Code.
    ' Button setup at startup
    LOW 5
    FOR counter = 1 TO 127
    PULSOUT 6, 1
    PAUSE 5
    NEXT
    Volume = 0
    DO
    GOSUB Get_Ir_Remote_Code
    DEBUG CLS, "Volume = : ", DEC Volume

    LOW 5
    IF (remoteCode = 19) THEN
    PULSOUT 6, 1
    PAUSE 20
    SELECT volume
    CASE 1 TO 127
    volume = volume - 1
    ENDSELECT
    ELSEIF (remoteCode = 18) THEN
    HIGH 5
    PULSOUT 6, 1
    SELECT volume
    CASE 0 TO 126
    volume = volume + 1
    ENDSELECT
    PAUSE 20
    ELSE
    PAUSE 100
    ENDIF
    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 ' Clear all bits in remoteCode
    ' Wait for resting state between messages to end.

    DO
    RCTIME IrDet, 1, irPulse
    LOOP UNTIL irPulse > 1000
    ' Measure start pulse. If out of range, then retry at Get_Ir_Remote_Code.
    RCTIME 9, 0, irPulse
    IF irPulse > 1125 OR irPulse < 675 THEN GOTO Get_Ir_Remote_Code
    ' Get data bit pulses.
    RCTIME IrDet, 0, irPulse ' Measure pulse
    IF irPulse > 300 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

    RETURN
Sign In or Register to comment.