#include <IRremote.h>
#define N00 0x80BFE11E
#define N01 0x80BF49B6
#define N02 0x80BFC936
#define N03 0x80BF33CC
#define N04 0x80BF718E
#define N05 0x80BFF10E
#define N06 0x80BF13EC
#define N07 0x80BF51AE
#define N08 0x80BFD12E
#define N09 0x80BF23DC
#define RAW_HDR_MARK 3350
#define RAW_HDR_SPACE 1800
#define RAW_BIT_MARK 400
#define RAW_ONE_SPACE 1350
#define RAW_ZERO_SPACE 500
#define RAW_RPT_MARK 400
#define RAW_RPT_SPACE 16950
int rawData_Bits = 144 ;
byte rawData_0[18] = { 0xC4, 0xD3, 0x64, 0x80, 0x0, 0x0, 0x18, 0xB0, 0x6C, 0x2, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8 };
byte rawData_1[1] = { 0 };
byte rawData_2[1] = { 0 };
byte rawData_3[1] = { 0 };
byte rawData_4[1] = { 0 };
byte rawData_5[18] = { 0xC4, 0xD3, 0x64, 0x80, 0x0, 0x4, 0x18, 0x90, 0x6C, 0x22, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4C };
byte rawData_6[18] = { 0xC4, 0xD3, 0x64, 0x80, 0x0, 0x4, 0x18, 0x50, 0x6C, 0x2, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xF4 };
byte rawData_7[18] = { 0xC4, 0xD3, 0x64, 0x80, 0x0, 0x4, 0x18, 0xD0, 0x6C, 0x2, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xC };
byte rawData_8[18] = { 0xC4, 0xD3, 0x64, 0x80, 0x0, 0x4, 0x18, 0x30, 0x6C, 0x2, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8C };
byte rawData_9[18] = { 0xC4, 0xD3, 0x64, 0x80, 0x0, 0x4, 0x18, 0xB0, 0x6C, 0x2, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4C };
#define IR_NUM_SIZE 10
int recvPin = 2;
int Recv_Enable_LED_Pin = 10;
int LED_Buzzer_Pin = 11;
int khz = 38;
IRrecv irrecv(recvPin);
IRsend irsend;
decode_results results;
uint8_t IR_MAP_Index;
struct NUM_MAP {
unsigned long IR_CODE;
uint8_t INDEX_NUM;
};
static struct NUM_MAP IR_MAP[IR_NUM_SIZE] = {{N00, 0}, {N01, 1}, {N02, 2}, {N03, 3}, {N04, 4}, {N05, 5}, {N06, 6}, {N07, 7}, {N08, 8}, {N09, 9}};
void ST_LED_Buzzer (int Send_Status) {
while ( Send_Status > 0 ) {
if (Send_Status >= 5) {
digitalWrite(LED_Buzzer_Pin, HIGH);
delay(400);
digitalWrite(LED_Buzzer_Pin, LOW);
delay(400);
Send_Status = Send_Status - 5;
} else {
digitalWrite(LED_Buzzer_Pin, HIGH);
delay(150);
digitalWrite(LED_Buzzer_Pin, LOW);
delay(150);
Send_Status = Send_Status - 1;
}
}
}
void RAWIRSend(byte SendRAWData[], unsigned int SendRAWData_Len, unsigned int SendRAWData_Bits, unsigned int hz)
{
int Rep_Temp = 0;
unsigned int rawData_Bits_Count =0;
byte Mask = 1;
if (RAW_RPT_SPACE > 0) Rep_Temp = 2;
else Rep_Temp = 1;
irsend.enableIROut(hz);
irsend.space(max(RAW_HDR_MARK,RAW_HDR_SPACE));
for (int j = 0; j < Rep_Temp; j++) {
irsend.mark(RAW_HDR_MARK);
irsend.space(RAW_HDR_SPACE);
for (unsigned int i = 0; i < SendRAWData_Len; i++) {
for (Mask = B10000000; Mask > 0; Mask >>= 1) {
if (rawData_Bits_Count < SendRAWData_Bits) {
if (SendRAWData[i] & Mask) {
irsend.mark(RAW_BIT_MARK);
irsend.space(RAW_ONE_SPACE);
}
else {
irsend.mark(RAW_BIT_MARK);
irsend.space(RAW_ZERO_SPACE);
}
rawData_Bits_Count++;
}
}
}
if (Rep_Temp > 1) {
irsend.mark(RAW_RPT_MARK);
irsend.space(RAW_RPT_SPACE);
}
irsend.space(max(RAW_HDR_MARK,RAW_HDR_SPACE));
}
}
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(Recv_Enable_LED_Pin, OUTPUT);
pinMode(LED_Buzzer_Pin, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(Recv_Enable_LED_Pin, HIGH);
digitalWrite(LED_Buzzer_Pin, LOW);
digitalWrite(13, HIGH);
}
void loop() {
if (irrecv.decode(&results)) {
if (results.decode_type == NEC) {
Serial.print("NEC Code : ");
Serial.print(results.value, HEX);
IR_MAP_Index = IR_NUM_SIZE;
for (uint8_t i = 0; i < IR_NUM_SIZE; i++) {
if (results.value == IR_MAP[i].IR_CODE) {
IR_MAP_Index = IR_MAP[i].INDEX_NUM;
break;
}
}
Serial.print(" Map Index : ");
Serial.println(IR_MAP_Index, DEC);
if (IR_MAP_Index < IR_NUM_SIZE) {
delay(100);
switch (IR_MAP_Index) {
case 0:
ST_LED_Buzzer (10);
RAWIRSend(rawData_0, sizeof(rawData_0) / sizeof(rawData_0[0]), rawData_Bits, khz);
break;
case 1:
ST_LED_Buzzer (1);
RAWIRSend(rawData_1, sizeof(rawData_1) / sizeof(rawData_1[0]), rawData_Bits, khz);
break;
case 2:
ST_LED_Buzzer (2);
RAWIRSend(rawData_2, sizeof(rawData_2) / sizeof(rawData_2[0]), rawData_Bits, khz);
break;
case 3:
ST_LED_Buzzer (3);
RAWIRSend(rawData_3, sizeof(rawData_3) / sizeof(rawData_3[0]), rawData_Bits, khz);
break;
case 4:
ST_LED_Buzzer (4);
RAWIRSend(rawData_4, sizeof(rawData_4) / sizeof(rawData_4[0]), rawData_Bits, khz);
break;
case 5:
ST_LED_Buzzer (5);
RAWIRSend(rawData_5, sizeof(rawData_5) / sizeof(rawData_5[0]), rawData_Bits, khz);
break;
case 6:
ST_LED_Buzzer (6);
RAWIRSend(rawData_6, sizeof(rawData_6) / sizeof(rawData_6[0]), rawData_Bits, khz);
break;
case 7:
ST_LED_Buzzer (7);
RAWIRSend(rawData_7, sizeof(rawData_7) / sizeof(rawData_7[0]), rawData_Bits, khz);
break;
case 8:
ST_LED_Buzzer (8);
RAWIRSend(rawData_8, sizeof(rawData_8) / sizeof(rawData_8[0]), rawData_Bits, khz);
break;
case 9:
ST_LED_Buzzer (9);
RAWIRSend(rawData_9, sizeof(rawData_9) / sizeof(rawData_9[0]), rawData_Bits, khz);
break;
}
irrecv.enableIRIn();
} else {
irrecv.resume();
}
}
irrecv.resume();
}
}