IRIN and a switch.

julianE

Senior Member
I'm making an input selector for an amplifier. I want to control it with a picaxe, it will have an Infrared remote control and also a single button that will go through 4 choices. The IR command is blocking, what would be the best way to sense for switch closure, should I go with an interrupt or perhaps use the IRIN timeout set for 1/2 a second and all run in a loop. Thanks in advance,
 

hippy

Technical Support
Staff member
If an IRIN without a timeout is used it will block and an interrupt won't bring it out of blocking prematurely. A timeout and button check would seem the easiest way but there is another and that is to repeatedly poll the IR signal same as a button.

Providing the IR remote sends commands repeatedly when a button is held you can afford to miss the first IR command and catch the second, something like ...
Code:
Symbol BTN_PIN = pinC.0
Symbol IR_PIN  = pinC.1 : Symbol IR = C.1

MainLoop:
  Do
    If IR_PIN  = 0 Then Gosub IrSeen
    If BTN_PIN = 1 Then Gosub ButtonPushed
  Loop

IrSeen:
  Do
    IrIn [1000,NoIrCommand], IR, b0
    SerTxd( "Got IR command ", #b0, CR, LF )
  Loop
NoIrCommand:
  Return

ButtonPushed:
  SerTxd( "Button Pushed", CR, LF )
  Do : Loop Until BTN_PIN = 0
  Return
 

julianE

Senior Member
Thanks Hippy, you are amazing. I will test and report back, I was hesitant to post the question because it looks simple on the surface. Thanks again.
 

inglewoodpete

Senior Member
A few years ago, I built a home theatre controller that used two PICAXE chips. An 08M2 was used for the IR receiver, also driving an LED via its PWM pin. The LED provided dull 'standby' illumination and flashed brighter when an valid IR signal was received.

The main microcontroller polled the front panel buttons and also polled a connection from the IR receiver PICAXE to receive incoming IR commands. It controlled relays, digital volume controls and the TV via a serial connection. The main controller was a 40X2 but my setup was quite complex - in a smaller setup the second chip could easily be a 14M2 or other, smaller PICAXE.
 

erco

Senior Member
IRIN with a timeout of 20 or 30 in a tight loop checking for keypresses works fine. I like tiny code.
 

julianE

Senior Member
Hippy, I finally got around to testing the code, it's astonishing the time it takes to put a project in a plastic box, the only box i had on hand was a very tight fit, stuffed everything in but it came out none too pretty. Your code worked perfectly, thanks again. Inglewoodpete and erco, thanks for your feedback. Inglewoodpete, your project is way too ambitious for me, i'm just switching 4 inputs going to an amplifier from the 80's that had only 4 inputs. nowhere enough with all the sources we have now.
 
Top