Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:04 11 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : IR toggles output pin

Author Message
Dr. Diode

Newbie

Joined: 28/06/2014
Location: United States
Posts: 4
Posted: 01:50pm 07 Jul 2014
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2927
Posted: 03:09pm 07 Jul 2014
Copy link to clipboard 
Print this post

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 States
Posts: 4
Posted: 04:22pm 07 Jul 2014
Copy link to clipboard 
Print this post

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: Australia
Posts: 6220
Posted: 04:48pm 07 Jul 2014
Copy link to clipboard 
Print this post

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
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025