/*
   Código demonstrativo para a aula de Sistemas Embarcados,
   Curso de Ciência da Computação e Engenharia da Computação
   EEP.
*/

#include <IRremote.hpp>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20, 16, 2);

int RECV_PIN = 11;

void setup() {

  IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK);

  lcd.init();
  lcd.backlight();
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print(" Escola de Eng. ");
  lcd.setCursor(0, 1);
  lcd.print(" de  Piracicaba ");

  delay(3000);

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("    Sistemas    ");
  lcd.setCursor(0, 1);
  lcd.print("   Embarcados   ");

  delay(3000);

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("   Exercicio    ");
  lcd.setCursor(0, 1);
  lcd.print("----------------");

  delay(3000);

  lcd.clear();

}

void loop() {

  lcd.setCursor(0, 0);
  lcd.print("Press. uma tecla");
  lcd.setCursor(0, 1);
  lcd.print("Controle  Remoto");

  if (IrReceiver.decode()) {

    //IrReceiver.printIRResultShort(&Serial);
    //Serial.println();

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Address DEC:    ");
    lcd.setCursor(0, 1);
    lcd.print(IrReceiver.decodedIRData.address, DEC);
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Address HEX:    ");
    lcd.setCursor(0, 1);
    lcd.print(IrReceiver.decodedIRData.address, HEX);
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Command DEC:    ");
    lcd.setCursor(0, 1);
    lcd.print(IrReceiver.decodedIRData.command, DEC);
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Command HEX:    ");
    lcd.setCursor(0, 1);
    lcd.print(IrReceiver.decodedIRData.command, HEX);
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Raw Data DEC:   ");
    lcd.setCursor(0, 1);
    lcd.print(IrReceiver.decodedIRData.decodedRawData, DEC);
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Raw Data HEX:   ");
    lcd.setCursor(0, 1);
    lcd.print(IrReceiver.decodedIRData.decodedRawData, HEX);
    delay(2000);

    lcd.clear();
    /*

          Serial.println("Raw Data");
          Serial.println("------------------------------------");
          Serial.print("Decimal: ");
          Serial.println(IrReceiver.decodedIRData.decodedRawData, DEC);
          Serial.print("Hexa: ");
          Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
          Serial.println();

          // if (IrReceiver.decodedIRData.decodedRawData == 0XFD08F7) { }
    */
    IrReceiver.resume();

  }

  delay(100);

}