Remote Receiver for KODI
 Page :   [ 1 ]    [ 2 ]    [ 3 ]    [ 4 ]    [ 5 ]  

This is the first go around for the software and could probably go for a bit of cleaning up in the future :)

First up is the software running on the Atmega328 (Arduino).  Basically this taskes the IR input from the remote and sends it via serial to the ESP.

 

/*
 * the IR library used was the library from
 * Ken Shirriff
 * http://arcfn.com
 */


/*
the codes from a crap remote i used for testing and the apple remote i use
            generic               apple
up    : FF18E7 16718055    77E1D0F3 2011287795
down  : FF4AB5 16730805    77E1B0F3 2011279603
left  : FF10EF 16716015    77E110F3 2011238643
right : FF5AA5 16734885    77E1E0F3 2011291891
select: FF38C7 16726215    77E1BAF3 2011282163
play  : FF52AD 16732845    77E17AF3 2011265779
back  : FF42BD 16728765    77E140F3 2011250931

*/

#include <IRremote.h>
#include <SoftwareSerial.h>

#define VALUE_UP 2011287795
#define VALUE_DOWN 2011279603
#define VALUE_LEFT 2011238643
#define VALUE_RIGHT 2011291891
#define VALUE_SELECT 2011282163
#define VALUE_PLAY 2011265779
#define VALUE_BACK 2011250931


SoftwareSerial mySerial(8, 9); // RX, TX

int RECV_PIN = 6;
int LED_PIN = 7;

volatile long value = 0;
IRrecv irrecv(RECV_PIN);

decode_results results;



unsigned long previousLedMillis = 0;
const long intervalLed = 250;


unsigned long previousMillis = 0;
const long interval = 250;

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  pinMode(RECV_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);  

  irrecv.enableIRIn(); // Start the receiver

  mySerial.begin(4800);

  
}

void loop() {

  unsigned long currentMillis = millis();

  if (currentMillis - previousLedMillis >= intervalLed) {

    previousLedMillis = currentMillis;
    digitalWrite(LED_PIN, LOW);

  }
  if (irrecv.decode(&results)) {

      digitalWrite(LED_PIN, HIGH);

    if (results.value != 4294967295){
      value = results.value;
    }

  if (currentMillis - previousMillis >= interval) {

    previousMillis = currentMillis;

    int sendValue = 0;

    switch (value) {
      case VALUE_UP: // up
        sendValue = 1;
        break;
      case VALUE_DOWN: // down
        sendValue = 2;
        break;
      case VALUE_LEFT: // left
        sendValue = 3;
        break;
      case VALUE_RIGHT: // right
        sendValue = 4;
        break;
      case VALUE_SELECT: // select
        sendValue = 5;
        break;
      case VALUE_PLAY: // play/pause
        sendValue = 6;
        break;
      case VALUE_BACK: // back
        sendValue = 7;
        break;
      default:
        break;
    }

    if (sendValue > 0){

      mySerial.write(sendValue);
      
    }

  }        
    
    irrecv.resume(); // Receive the next value

  }
  delay(100);
}

 

The next page lists the code running on the ESP.

 

(Page 4 of 5)