IR code to switch relay "twitchy"
Xlrator
Posts: 8
I have been working on this for two days and so far so good. I'm toggling a relay on/off thru a flip-flop (CD4013). I can change states with a tact. switch and with a BS2 Homework Board with IR.
I am using some of the code that I found for the BoeBot IR Remote kit and it works well, however when the button is held down a little too long it will just switch to ON then OFF real fast. Sometimes I find myself clicking a couple times to get it in the state that I want. What I want it to be is if the button is held down it will only switch once. I had tried PULSOUT but I had the same results.
I'm not sure how much of the code is necessary so I will paste the whole thing I am using at the moment. I'm not the greatest at BASIC but if there is another command I should look into, someone should be able to point me in the right direction.
I am using some of the code that I found for the BoeBot IR Remote kit and it works well, however when the button is held down a little too long it will just switch to ON then OFF real fast. Sometimes I find myself clicking a couple times to get it in the state that I want. What I want it to be is if the button is held down it will only switch once. I had tried PULSOUT but I had the same results.
I'm not sure how much of the code is necessary so I will paste the whole thing I am using at the moment. I'm not the greatest at BASIC but if there is another command I should look into, someone should be able to point me in the right direction.
' Ir Remote Application - IrRemoteCodeCapture.bs2 ' Process incoming SONY remote messages & display remote code. ' {$STAMP BS2} ' {$PBASIC 2.5} ' SONY TV IR remote variables irPulse VAR Word ' Stores pulse widths remoteCode VAR Byte ' Stores remote code DEBUG "Press/release remote buttons..." DO ' Main DO...LOOP Get_Pulses: ' Label to restart message check remoteCode = 0 ' Clear previous remoteCode ' Wait for resting state between messages to end. DO RCTIME 9, 1, irPulse LOOP UNTIL irPulse > 1000 ' Measure start pulse. If out of range, then retry at Get_Pulses label. RCTIME 9, 0, irPulse IF irPulse > 1125 OR irPulse < 675 THEN GOTO Get_Pulses ' Get Data bit pulses. RCTIME 9, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT0 = 1 RCTIME 9, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT1 = 1 RCTIME 9, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT2 = 1 RCTIME 9, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT3 = 1 RCTIME 9, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT4 = 1 RCTIME 9, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT5 = 1 RCTIME 9, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT6 = 1 ' Map digit keys to actual events. IF (remoteCode = 54) THEN HIGH 0 PAUSE 5000 LOW 0 DEBUG CLS, ? remoteCode LOOP