Created
December 7, 2010 09:25
-
-
Save yoggy/731613 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// Apple_Remote_Keyboard_Emulator.pde | |
// (prototype, not tested...) | |
// | |
// UsbKeyboard | |
// http://code.google.com/p/vusb-for-arduino/downloads/list | |
// http://www.practicalarduino.com/projects/easy/virtual-usb-keyboard | |
// | |
// IRremote.h | |
// http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html | |
// | |
#include "UsbKeyboard.h" | |
#include "IRremote.h" | |
// | |
#define KEY_ARROW_RIGHT 0x4F | |
#define KEY_ARROW_LEFT 0x50 | |
#define KEY_ARROW_DOWN 0x51 | |
#define KEY_ARROW_UP 0x52 | |
// for IR Reciever | |
int RECV_PIN = 11; | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() | |
{ | |
irrecv.enableIRIn(); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
UsbKeyboard.update(); | |
if (irrecv.decode(&results)) { | |
// for apple remote protocol | |
char val = (results.value >> 8) & 0xFF; | |
switch(val) { | |
case 0x20: | |
Serial.println("play"); | |
UsbKeyboard.sendKeyStroke(KEY_ENTER); | |
break; | |
case 0x40: | |
// menu | |
Serial.println("menu"); | |
UsbKeyboard.sendKeyStroke(KEY_ENTER); | |
break; | |
case 0x10: | |
Serial.println("rev"); | |
UsbKeyboard.sendKeyStroke(KEY_ARROW_LEFT); | |
break; | |
case 0xE0: | |
Serial.println("fwd"); | |
UsbKeyboard.sendKeyStroke(KEY_ARROW_RIGHT); | |
break; | |
case 0xD0: | |
Serial.println("plus"); | |
UsbKeyboard.sendKeyStroke(KEY_ARROW_UP); | |
break; | |
case 0xB0: | |
Serial.println("minus"); | |
UsbKeyboard.sendKeyStroke(KEY_ARROW_DOWN); | |
break; | |
case 0xFF: | |
Serial.println("repeat code"); | |
break; | |
default: | |
break; | |
} | |
irrecv.resume(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment