View: 4479|Reply: 1

infra red remote hack - switch led on/off

[Copy link]

12

threads

30

posts

150

credits

Registered member

Rank: 2

credits
150
Published in 2016-1-4 01:08:35 | Show all floors |Read mode
I use Debian Jessie on an OPi-PC. I do : $modprobe sunxi_ir_rx
I have this cheap remote control (included with dvb-stick).
When I press the remote-keys I get characters in my terminal window.
(can somebody confirm that this works out of the box?)

I wrote a small program which makes use of this tremendous capacity! (no need for lirc! nor configuration! nor reading manual stuff!)
I did connect an LED to port PA_6 (pin number 7)

you can compile and test this with : gcc -o remote-led remote-led.c -lwiringPi
you need to change 'u' and '6' to your own remote output characters

----save as remote-led.c-----and remember-----I'm not a programmer----------
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>

//The WiringPi pin numbers used by our LEDs
#define LED3 6

#define ON 1
#define OFF 0

main()
{
if (wiringPiSetup () == -1)
            exit (1) ;
pinMode (LED3, OUTPUT);
char ch;
system("stty raw");//seting the terminal in raw mode - if not you need CR
while(1)
     {
     ch=getchar();
     // 6 is OFF ---- u in ON --- remotecontrol output in terminalwindow
     if(ch=='u') digitalWrite(LED3, ON);
     if(ch=='6') digitalWrite(LED3, OFF);
     if(ch=='q'){          //terminate or come out of raw mode on "q" pressed
          system("stty cooked");
          exit(0); //or terminate
     }
//      printf("you pressed %c\n ",ch);  //write rest code here
     }

}

4

threads

44

posts

165

credits

Registered member

Rank: 2

credits
165
Published in 2016-1-4 04:07:50 | Show all floors
Really interesting... Need to try it out once my boards arrive. Something this simple has many advantages...
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list