Created
January 7, 2012 22:19
-
-
Save hugoreinaldo/1576248 to your computer and use it in GitHub Desktop.
Arduino IR Receiver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// from http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html | |
// | |
#include <IRremote.h> | |
int RECV_PIN = 11; | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() | |
{ | |
Serial.begin(9600); | |
irrecv.enableIRIn(); // Start the receiver | |
} | |
void loop() { | |
if (irrecv.decode(&results)) { | |
Serial.println(results.value, HEX); | |
irrecv.resume(); // Receive the next value | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding: latin-1 | |
# | |
# www.entrebits.com.br | |
# | |
import serial | |
import time | |
import sys | |
import os | |
def main(): | |
serial_port = '/dev/ttyACM0' | |
if len(sys.argv) > 1: | |
serial_port = sys.argv[1] | |
serialFd = serial.Serial(serial_port, 9600) | |
print 'configurando...' | |
key_map = get_keys(serialFd) | |
while True: | |
data = serial_getkey(serialFd, 0.5) | |
for key in key_map: | |
if key_map[key] == data: | |
print 'pressing {0}'.format(key) | |
os.system('xdotool key {0}'.format(key)) | |
def get_keys(fd): | |
key_map = {'Left': None, | |
'Right': None, | |
'Up': None, | |
'Down': None} | |
while key_map.values().count(None): | |
for key in key_map: | |
if key_map[key] == None: | |
print 'pressione o botao correspondente a tecla {0}'.format(key) | |
data = serial_getkey(fd) | |
key_map[key] = data | |
print 'key={0}, value={1}'.format(key, data) | |
return key_map | |
def serial_getkey(fd, debouncer=1): | |
data = fd.readline() | |
data = data.rstrip() | |
time.sleep(debouncer) | |
toFlush = fd.inWaiting() | |
if toFlush: fd.read(toFlush) | |
return data | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment