![]() |
Forum Index : Microcontroller and PC projects : IR toggles output pin
Author | Message | ||||
Dr. Diode![]() Newbie ![]() Joined: 28/06/2014 Location: United StatesPosts: 4 |
How does one toggle an output pin from 1 to 0 as a result of detecting the same keycode from an IR transmitter? This would be similar to the function of the MUTE key, that is pressed once an output is driven high and latches. Released and then pressed again, the output is driven low and latches. Thank you for the help. |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2927 |
This is easy to do - base it on the example given on Page 16 of the MicroMite User Manual ('Special Hardware Devices' chapter, 'Infrared Remote Control Decoder' section). [code] Lout = 15 'Pin number of Latched output setpin(Lout), dout 'set latched output to digital output (used Pin15 here as ok for 28-pin and 44-pin uMites) PState = 0 'variable to store Pin Status PIN(Lout) =0 'initially switch off latched output IR DevCode, KeyCode, IR_Int DO < main program here > LOOP IR_Int: IF DevCode =DC AND KeyCode = KC THEN 'Set DC to the required DeviceCode. Similarly set KC to required KeyCode IF PState=0 THEN 'toggle Latched output - if off now then switch on PIN(Lout) = 1 PState = 1 ELSE 'if on now then switch off PIN(Lout) = 0 PState = 0 ENDIF PAUSE 100 'play around with duration to obtain desired results (may not even need this line!) ENDIF IReturn [/code] There are many ways to 'tidy' this code but for now I hope this helps you get underway . . . . WW |
||||
Dr. Diode![]() Newbie ![]() Joined: 28/06/2014 Location: United StatesPosts: 4 |
Hello WhiteWizard, As with the code I was experimenting with, your suggestion causes the output pin to cycle high and low if the transmitter key remains pressed. For what it's worth, in the PICAXE world this problem had no solution until later versions of the PICAXE IR command supported a "timeout feature". That said, I very much appreciate your reply. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6220 |
You could use the TIMER function to limit the IR interrupt from doing anything until it has been quite for one second: Lout = 15 'Pin number of Latched output
SETPIN(Lout), DOUT 'set latched output to digital output (used Pin15 here as ok for 28-pin and 44-pin uMites) PState = 0 'variable to store Pin Status PIN(Lout) =0 'initially switch off latched output IR DevCode, KeyCode, IR_Int DO < main program here > LOOP IR_Int: IF TIMER > 1000 THEN' one second with no interupt required IF DevCode =DC AND KeyCode = KC THEN 'Set DC to the required DeviceCode. Similarly set KC to required KeyCode IF PState=0 THEN 'toggle Latched output - if off now then switch on PIN(Lout) = 1 PState = 1 ELSE 'if on now then switch off PIN(Lout) = 0 PState = 0 ENDIF PAUSE 100 'play around with duration to obtain desired results (may not even need this line!) ENDIF ENDIF TIMER = 0 ' reset the timer to zero IRETURN The only change to the previous code is the TIMER test at the start of the IR routine and a TIMER reset at the end. I don't have any IR setup to test it with. Jim VK7JH MMedit |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |