Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 2149|Reply: 1

infra red remote hack - switch led on/off

[Copy link]

12

Threads

30

Posts

150

Credits

Registered member

Rank: 2

Credits
150
Post time 2016-1-4 01:08:35 | Show all posts |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
Post time 2016-1-4 04:07:50 | Show all posts
Really interesting... Need to try it out once my boards arrive. Something this simple has many advantages...
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-12-9 05:44 GMT+8 , Processed in 0.028211 second(s), 22 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list