Stap 6: Erstellen des endgültigen programma's IR2Key.ino
Alle gewünschten Fernbedienungstasten wurden erfasst und notiert.
Im dem zu erstellenden schets IR2Key.ino wird eine Zuordnung zwischen IR-Singnal und KODI-Tastaturbefehl nach folgendem Muster vorgenommen:
* play - p // KODI Tastaturbefehl #define PLAY 0xB676A3B2 // IR-Signal im HEX-Format PLAY zuordnen #define PLAY_KEY Keyboard.write(112); // ASCII for p PLAY_KEY zuordnen case PLAY: // Arduino/Genuino-Code - wenn PLAY erfasst, dann PLAY_KEY; // PLAY_KEY (also "p"') ausführen break;
Für meine Fernbedienung ergibt sich folgendes Programm IR2KeyJW.ino:
/* * IR2KeyJW: based on IRrevcDemo (Version 0.1 July, 2009) of Ken Shirriff arcfn.com * Remote signal to keyboard use with openELEC * An IR detector/demodulator must be connected to the input RECV_PIN. * Modified by JensLab at Feb, 2015 * OpenELEC / kodi - shortcuts * play - p * play/pause - space * stop - x * vorlauf - f * rücklauf - r * up - pfeil nach oben * left - pfeil nach links * right - pfeil nach rechts * down - pfeil nach unten * select - enter * shutdown menue - s * back - backspace (loeschen) * exit - escape */ #include int RECV_PIN = 5; IRrecv irrecv(RECV_PIN); decode_results results; // Recorded IRcodes (here SAMSUNG-TV Remote) #define PLAY 0xB676A3B2 #define STOP 0x1478EC78 #define FORWARD 0x395AECF4 #define REWIND 0xC1E6EB16 #define UP 0xE8105F4 #define DOWN 0x1114CBF6 #define LEFT 0xC1A1B332 #define RIGHT 0x9F953498 #define ENTER 0xD7064AD8 #define EXIT 0x558A0912 #define BACK 0xB2D45698 // menue button #define POWER 0x40CF3F38 // shutdown menu // Mediaplayer hot keys #define PLAY_KEY Keyboard.write(112); // ASCII for p //Keyboard.write(32); // ASCII code for space #define STOP_KEY Keyboard.write(120); // ASCII for x #define FORWARD_KEY Keyboard.write(102); // ASCII for f #define REWIND_KEY Keyboard.write(114); // ASCII for r #define UP_KEY Keyboard.write(KEY_UP_ARROW); // Keyboard.press(KEY_UP_ARROW); delay(100); Keyboard.releaseAll(); #define DOWN_KEY Keyboard.write(KEY_DOWN_ARROW); // Keyboard.press(KEY_DOWN_ARROW); delay(100); Keyboard.releaseAll(); #define LEFT_KEY Keyboard.write(KEY_LEFT_ARROW); // Keyboard.press(KEY_LEFT_ARROW); delay(100); Keyboard.releaseAll(); #define RIGHT_KEY Keyboard.write(KEY_RIGHT_ARROW); // Keyboard.press(KEY_RIGHT_ARROW); delay(100); Keyboard.releaseAll(); #define ENTER_KEY Keyboard.write(KEY_RETURN); #define EXIT_KEY Keyboard.write(KEY_ESC); #define BACK_KEY Keyboard.write(KEY_BACKSPACE); // menue button #define POWER_KEY Keyboard.write(115); // ASCII for s, shutdown menu void setup() { Serial.begin(9600); // for debugging irrecv.enableIRIn(); // Start the receiver Keyboard.begin(); // Start keyboard } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); // for debugging // select action response to IR input switch(results.value) { case PLAY: PLAY_KEY; break; case STOP: STOP_KEY break; case FORWARD: FORWARD_KEY break; case REWIND: REWIND_KEY break; case UP: UP_KEY break; case DOWN: DOWN_KEY break; case LEFT: LEFT_KEY break; case RIGHT: RIGHT_KEY break; case ENTER: ENTER_KEY break; case EXIT: EXIT_KEY break; case BACK: BACK_KEY break; case POWER: POWER_KEY break; } irrecv.resume(); // Receive the next value } }
Dieses Programm auf den Leonardo kompatiblen Microcontroller (Arduino/waar) hochladen.