In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Jimbo wrote: Hello, I am trying to convert a BS2 program from the understanding signals book to SX code. Reading the SX help file it looks like you cannot build an array with word. The compiler gives you an invalid parameter error. I thought I could just make individual VARiables ie; IR_pulse0 - IR_Pulse12 but, when it reaches IR_Pulse9 I get variable exceed available ram. What I want to do is to capture and indentify the key I pressed on my remote. The final objective is to build a learning remote to combine the 5 remotes I currently have. (I know I can buy one but this would be a great learning exersize.) If I can ever get this working I will post the final project in the sand box. Here is the program I'm trying to convert. Comments from me are preceeded by *** Thanks, Jim W. ' -----[ Program Title and Description ]----------------------------------- ' Understanding Signals - DecodeSonyIRRemote.bs2 ' Decode 38 kHz Sony IR TV remote control signal. ' Author: Andy Lindsay, Parallax, Inc. ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ I/O Definitions ]------------------------------------------------- IR_detect PIN 8 ' IR detector output -> P8. ' -----[ Constants ]------------------------------------------------------- active_high CON 1 ' Used to set PULSIN commands active_low CON 0 ' to detect +/- pulses. ' -----[ Variables ]------------------------------------------------------- ' This program reads all the pulses delivered by the remote, but in ' practice, only the first two to five pulses are required. This can be ' used To save seven To 9 Words in RAM (in this section) and the same ' number OF PULSIN commands in the Process IR Pulses subroutine. IR_pulse VAR Word(12) '***This will cause Invalid parameter counter VAR Nib '*** SX doesn't seem to like Nib's changed to bytes type VAR Nib IR_message VAR Byte ' -----[ Initialization ]-------------------------------------------------- DEBUG CLS ' BOE reset clears display. ' -----[ Main Routine ]---------------------------------------------------- DO DO ' Wait for IR detector output LOOP UNTIL IR_Detect = 0 ' to go low. GOSUB Display_Heading GOSUB Find_and_Display_Start_Pulse GOSUB Process_IR_Pulses GOSUB Display_IR_Pulse_Values GOSUB Convert_to_Binary_Number_Display LOOP ' -----[ Subroutine - Display Heading in Debug Terminal ]------------------ Display_Heading: DEBUG HOME ' *** I can display stuff like this on my hc4led DEBUG "IR Remote Messages ", CR, CR DEBUG "Pulse Duration Value", CR DEBUG "-------------------------------", CR RETURN ' -----[ Subroutine - Find and Display Start Pulse ]----------------------- ' Packets are delivered around 20 times/second while a given button on the ' remote is pressed and held. This program extracts a start pulse from ' an earlier packet. The Process IR Pulses subroutine pickes up the rest ' of the pulse values a few packets later. In remote controlled ' the duration of the start pulse can simply be discarded. Find_and_Display_Start_Pulse: FOR counter = 0 TO 15 PULSIN IR_detect,active_low,IR_pulse(0) IF IR_pulse(0) > 900 THEN DEBUG "Start" DEBUG " = ", DEC5 IR_pulse(0) * 2, " us " DEBUG " Start Bit", CR EXIT ' Exit FOR...NEXT after start ENDIF ' pulse is detected. NEXT RETURN ' -----[ Subroutine - Process IR Pulses ]---------------------------------- Process_IR_Pulses: DO PULSIN IR_detect,active_high,IR_pulse(0) LOOP UNTIL (IR_pulse(0) > 1400) AND (IR_pulse(0) <> 0) ' The BASIC Stamp 2p and 2SX modules are fast enough to load these ' values using a FOR...NEXT loop, but all other modules should load the ' pulse values as a sequence of PULSIN Commands. PULSIN IR_detect,active_low,IR_pulse(0)'*** Here is where I'm Stuck PULSIN IR_detect,active_low,IR_pulse(1) PULSIN IR_detect,active_low,IR_pulse(2) PULSIN IR_detect,active_low,IR_pulse(3) PULSIN IR_detect,active_low,IR_pulse(4) PULSIN IR_detect,active_low,IR_pulse(5) PULSIN IR_detect,active_low,IR_pulse(6) PULSIN IR_detect,active_low,IR_pulse(7) PULSIN IR_detect,active_low,IR_pulse(8) PULSIN IR_detect,active_low,IR_pulse(9) PULSIN IR_detect,active_low,IR_pulse(10) PULSIN IR_detect,active_low,IR_pulse(11) RETURN ' -----[ Subroutine - Display IR Pulse Values ]---------------------------- Display_IR_Pulse_Values: FOR counter = 0 TO 10 DEBUG " ", DEC2 counter DEBUG " = ", DEC5 IR_pulse(counter) * 2, " us " IF IR_pulse(counter) > 450 THEN DEBUG " Binary-1", CR ELSE DEBUG " Binary-0", CR ENDIF NEXT RETURN ' -----[ Subroutine - Convert to Binary Number Display ]------------------- Convert_to_Binary_Number_Display: ' Subroutine FOR counter = 0 TO 10 IF (IR_pulse(counter) < 450) THEN IR_message.LOWBIT(counter) = 0 ELSE IR_message.LOWBIT(counter) = 1 ENDIF NEXT DEBUG CR,CR,"Binary Value: ", BIN8 IR_message, CR DEBUG "Decimal Value: ", DEC3 IR_message, CR DEBUG "Without bit-7: " DEBUG " ",DEC3 IR_message & %01111111,CR RETURN ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=139808 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)