IR remote help
I am trying to use the IR remote object and I can't quite get it to work.
I would like to set a pin (13) high if chUp is pressed, and set a pin (14) high if chDn is pressed.
This is probably really easy, but please bear with me as I am still learning.
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The pessimist is never disappointed.
I would like to set a pin (13) high if chUp is pressed, and set a pin (14) high if chDn is pressed.
This is probably really easy, but please bear with me as I am still learning.
Thanks.
PUB Main
DirA[noparse][[/noparse]6] := In 'Sets pin 6 to In
Dira[noparse][[/noparse]13] := Out 'Sets pin 13 to Out
Dira[noparse][[/noparse]14] := Out 'Sets pin 14 to Out
Outa[noparse][[/noparse]13] := 0 'Sets pin 13 to Low
Outa[noparse][[/noparse]14] := 0 'Sets pin 14 to Low
Start(6, @code)
repeat
value := GetSonyCode(6, @code)
if value == 16
outa[noparse][[/noparse]13] := 1
elseif value == 17
outa[noparse][[/noparse]14] := 1
PUB Start(Pin, addrMainCode) : result
{{
Pin - propeller pin connected to IR receiver
addrMainCode - address of keycode variable in main memory
}}
stop
byte[noparse][[/noparse]addrMainCode] := NoNewCode
cog := cognew(getSonycode(Pin, addrMainCode), @Stack) + 1
result := cog
PUB Stop
{{
stop cog if in use
}}
if cog
cogstop(cog~ -1)
PUB getSonyCode(pin, addrMainCode) | irCode, index, pulseWidth, lockID
{{
Decode the Sony TV Remote key code from pulses received by the IR receiver
}}
' wait for idle period (ir receiver output = 1 for gapMin)
' comment out "auto repeat" code if auto key repeat is desired
' start of "auto repeat" code section
dira[noparse][[/noparse]pin]~
index := 0
repeat
if ina[noparse][[/noparse]Pin] == 1
index++
else
index := 0
while index < gapMin
' end of "auto repeat" code section
frqa := 1
ctra := 0
dira[noparse][[/noparse]pin]~
' wait for a start pulse ( width > startBitMin and < startBitMax )
repeat
ctra := (%10101 << 26 ) | (PIN) ' accumulate while A = 0
waitpne(0 << pin, |< Pin, 0)
phsa:=0 ' zero width
waitpeq(0 << pin, |< Pin, 0) ' start counting
waitpne(0 << pin, |< Pin, 0) ' stop counting
pulseWidth := phsa / (clkfreq / 1_000_000) + 1
while ((pulseWidth < startBitMin) OR (pulseWidth > startBitMax))
' read in next 12 bits
index := 0
irCode := 0
repeat
ctra := (%10101 << 26 ) | (PIN) ' accumulate while A = 0
waitpne(0 << pin, |< Pin, 0)
phsa:=0 ' zero width
waitpeq(0 << pin, |< Pin, 0) ' start counting
waitpne(0 << pin, |< Pin, 0) ' stop counting
pulseWidth := phsa / (clkfreq / 1_000_000) + 1
if (pulseWidth > oneBitMin) AND (pulseWidth < oneBitMax)
irCode := irCode + (1 << index)
index++
while index < 11
irCode := irCode & $7f ' mask off upper 5 bits
byte[noparse][[/noparse]addrMainCode] := irCode
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The pessimist is never disappointed.

Comments
The driver writes the code of the key pressed at the IR control to the variable for which you gave the adress in the start function.
Another thing: As the driver uses the pin, there is no need to set DIRA[noparse][[/noparse]6] to anything - each COG has it's own DIRA register and the direction has to be set by the driver.
So, in your repeat loop you simply use the code variable instead of the value.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The pessimist is never disappointed.