//**************
//IR sent demo v1.0
//Connect the IR send pins to D3 for this demo
//******************************
#include <IRSendRev.h>
int collision=2;
int k = 0; 
//unsigned char d[] = {9, 90, 91, 11, 31, 4, 1, 2, 3, 4};
unsigned char LED1[] = {15, 70, 70, 20, 60, 5, 1, 0, 0, 0,0};
unsigned char LED2[] = {15, 70, 70, 20, 60, 5, 2, 0, 0, 0,0};
unsigned char OFF[] = {15, 70, 70, 20, 60, 5, 3, 0, 0, 0,0};
//Very Important:
//the first parameter(15): the data that needs to be sent;
//the next 2 parameter(70,70): the logic high and low duration of "Start";
//the next 2 parameter(20,60): the logic "short" and "long"duration in the communication
//                             that to say:  if "0", the high duration is 20ms and  low is 20 ms; while logic "1",
//                              the high duration is 20 ms and low is 60 ms;
//the next 2 parameter(5): number of data you will sent;
//the next parameter(1, 0, 0, 0,0): data you will sent;
void setup()
{
    pinMode(collision,INPUT);
    Serial.begin(9600);
    
}

void loop()
{
     if(keyscan())
     {
         k=k+1;
         if(k>3)
         {
             k=1;
         }
       switch(k)
      {
         case 1:IR.Send(LED1, 38); Serial.println("LED1");
         break;//sent the data via 38Kz IR 
         case 2:IR.Send(LED2, 38);break;//sent the data via 38Kz IR  
         case 3:IR.Send(OFF, 38);break;//sent the data via 38Kz IR   
      }
  }
}
int keyscan(void)
{
   if(digitalRead(collision)==HIGH)
   {
        delay(10);
        if(digitalRead(collision)==HIGH)
        {
             while(digitalRead(collision));
             return 1;
        }
   }
   return 0;
}
