Shop OBEX P1 Docs P2 Docs Learn Events
Ir Help — Parallax Forums

Ir Help

CenlasoftCenlasoft Posts: 265
edited 2005-01-02 23:34 in General Discussion
I can't figure out whats wrong, Please help.

' Homemade IR Remote
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
IrLED······ VAR···· RA.0
'
' Constants
'
start_bit ·con ·1
stop_bit ·con ·4
bin_0 ··con ·2
IrMod··CON·38000···' modulation freq = 38 kHz
bin_1 ··con ·3
between_pulses ·con ·2
counter ·var ·byte
IR_message ·var ·byte
duration ·var ·byte
'
' Interrupt
'
IR_message = 25
' =========================================================================
· PROGRAM Start
' =========================================================================
'stop
'
' Program Code
'
Start:
Main:
freqout IrLED, IrMod, start_bit
pause between_pulses
for counter = 0 to 7
duration = 2 + IR_message.lowbit(counter)
freqout IRLED,IrMod,duration
pause between_pulses
next
freqout IRLED,IrMod,stop_bit
goto Main
Thanks,
Curtis

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-02 21:13
    There is no LOWBIT modifier in SX/B (remember, SX/B is similar to PBASIC, but not 100% compatible).·
    You can isolate the bit like this:

    Send_IR_Msg:
      temp1 = __PARAM1              ' copy of message
      FOR idx = 0 TO 7              ' send 8 bits 
        temp2 = temp1 & $01         ' get bit 0    
        temp2 = temp2 + 2           ' add zero timing
        GOSUB Ir_Modulate, temp2    ' module
        temp1 = temp1 >> 1          ' shift bits right 
        GOSUB Delay, 2, 1           ' inter-bit delay  
      NEXT
      RETURN
     
     
    IR_Modulate:
      temp3 = __PARAM1
      FREQOUT IrPin, IrFreq, temp3
      RETURN
     
     
    Delay:
      temp4 = __PARAM1
      temp5 = __PARAM2
      PAUSE temp4 * temp5
      RETURN
    
    

    I've busted things into subroutines to help you conserve program space.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • BeanBean Posts: 8,129
    edited 2005-01-02 23:34
    You can also do:

    temp2=2 + temp1.0

    instead of
    temp2=temp1 & $01
    temp2=temp2 + 2

    It is legal to add a bit to a bytevar.

    Bean.
Sign In or Register to comment.