//sajjadZangeneh 96231112
/*
  #include <IRremote.h>

  #define PIN_RECEIVER 2   // Signal Pin of IR receiver

  IRrecv receiver(PIN_RECEIVER);

  void setup()
  {
  Serial.begin(9600);
  receiver.enableIRIn(); // Start the receiver
  }

  void loop()
  {
  // Checks received an IR signal
  if (receiver.decode()) {
    translateIR();
    receiver.resume();  // Receive the next value
  }
  }


  void translateIR()
  {
  // Takes command based on IR code received
  switch (receiver.decodedIRData.command) {
    case 162:
      Serial.println("POWER");
      break;
    case 226:
      Serial.println("MENU");
      break;
    case 34:
      Serial.println("TEST");
      break;
    case 2:
      Serial.println("PLUS");
      break;
    case 194:
      Serial.println("BACK");
      break;
    case 224:
      Serial.println("PREV.");
      break;
    case 168:
      Serial.println("PLAY");
      break;
    case 144:
      Serial.println("NEXT");
      break;
    case 104:
      Serial.println("num: 0");
      break;
    case 152:
      Serial.println("MINUS");
      break;
    case 176:
      Serial.println("key: C");
      break;
    case 48:
      Serial.println("num: 1");
      break;
    case 24:
      Serial.println("num: 2");
      break;
    case 122:
      Serial.println("num: 3");
      break;
    case 16:
      Serial.println("num: 4");
      break;
    case 56:
      Serial.println("num: 5");
      break;
    case 90:
      Serial.println("num: 6");
      break;
    case 66:
      Serial.println("num: 7");
      break;
    case 74:
      Serial.println("num: 8");
      break;
    case 82:
      Serial.println("num: 9");
      break;
    default:
      Serial.println("Key is not define.");
  }
  }
*/

//problem : استفاده از switch_case

//sajjadZangeneh 96231112

#include <IRremote.h>
#define PIN_RECEIVER 2                        // Signal Pin of IR receiver
#define serail_rate 9600
uint8_t i;
uint8_t count = 20;

IRrecv receiver(PIN_RECEIVER);

const uint16_t KEY_MAP[] = {162, 226, 34, 2, 194, 224, 168, 144, 104, 152, 176, 48, 24, 122, 16, 56, 90, 66, 74, 82};
const char* VALUES[] = {"POWER", "MENU", "TEST", "PLUS", "BACK", "PREV.", "PLAY", "NEXT", "num: 0", "MINUS", "key: C", "num: 1",
                        "num: 2", "num: 3", "num: 4", "num: 5", "num: 6", "num: 7", "num: 8", "num: 9"
                       };
void setup()
{
  Serial.begin(serail_rate);
  receiver.enableIRIn();                       // Start the receiver
}

void loop()
{
  // Checks received an IR signal
  if (receiver.decode()) {
    translateIR();
    receiver.resume();                         // Receive the next value
  }
}

void translateIR()
{
  // Takes command based on IR code received
  for (i = 0 ; i < count ; i++) {
    if (receiver.decodedIRData.command == KEY_MAP[i]) {
      Serial.println(VALUES[i]);
      return;
    }
  }
  Serial.println("Key is not define.");
}