/* * IRusb - Provide USB keyboard/mouse control via an IR remote. * Runs on the Teensy, not a standard Arduino: http://www.pjrc.com/teensy/ * * An IR detector/demodulator must be connected to the input RECV_PIN (10). * This uses the IRremote library: http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html * * Copyright 2010 Ken Shirriff * http://arcfn.com */ #include int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { irrecv.enableIRIn(); // Start the receiver Serial.begin(9600); } int step = 1; unsigned long lastTime = millis(); #define GAP 200 // ms - gap between repeats void loop() { if (irrecv.decode(&results)) { // We want to repeat mouse moves as long as the button is pressed // but we don't want to repeat keypresses. So we wait for // a gap before processing keypresses. if (millis() - lastTime > GAP) { step = 1; } else if (step < 20) { step += 1; } switch (results.value) { case 0x9eb92: Mouse.move(0, -step); // up break; case 0x5eb92: Mouse.move(0, step); // down break; case 0xdeb92: Mouse.move(-step, 0); // left break; case 0x3eb92: Mouse.move(step, 0); //right break; default: if (millis() - lastTime > GAP) { switch (results.value) { case 0xd0b92: Mouse.click(); break; case 0x90b92: Keyboard.print("0"); break; case 0xb92: Keyboard.print("1"); break; case 0x80b92: Keyboard.print("2"); break; case 0x40b92: Keyboard.print("3"); break; case 0xc0b92: Keyboard.print("4"); break; case 0x20b92: Keyboard.print("5"); break; case 0xa0b92: Keyboard.print("6"); break; case 0x60b92: Keyboard.print("7"); break; case 0xe0b92: Keyboard.print("8"); break; case 0x10b92: Keyboard.print("9"); break; case 0x10: // RC5 vol up case 0x810: Serial.print(lastTime - millis(), DEC); Keyboard.set_key1(KEY_PAGE_UP); Keyboard.send_now(); Keyboard.set_key1(0); Keyboard.send_now(); break; case 0x11: // RC5 vol up case 0x811: Keyboard.set_key1(KEY_PAGE_DOWN); Keyboard.send_now(); Keyboard.set_key1(0); Keyboard.send_now(); break; default: Serial.print("Received 0x"); Serial.println(results.value, HEX); break; } } } lastTime = millis(); irrecv.resume(); // Resume decoding (necessary!) } }