#include <IRremote.h>
int redArray[] = {255,255,255,0,0,0,139};
int greenArray[] = {0,165,255,255,127,0,0};
int blueArray[] = {0,0,0,0,255,255,255};
 
//红绿蓝引脚
int redPin = 11;
int greenPin = 10;
int bluePin = 9;

//红外引脚
int IRPin = 3;

int index = 0;

//IRrecv irrecv(RECV_PIN);   // 红外遥控初始化
//decode_results results;   // 储存接收到的红外遥控信息
 
void setup()
{
  pinMode (redPin, OUTPUT);
  pinMode (greenPin, OUTPUT);
  pinMode (bluePin, OUTPUT);
  Serial.begin (9600);//波特率
  IrReceiver.begin (IRPin);//启动红外接收
}
 
void loop () {
  blink ();
  setColor (redArray [index], greenArray [index], blueArray [index]);
}

void setColor (int red,int green,int blue)
{
  digitalWrite (redPin, red);
  digitalWrite (greenPin, green);
  digitalWrite (bluePin, blue);
}

void blink (){
  if (IrReceiver.decode ()){
    String value = String (IrReceiver.decodedIRData.command, HEX);
    Serial.println (value);
    if (value.equals ("30")){ //向前快进
      Serial.println ("pre");
      index=0;
    }else if (value.equals("18")) { //向后快进
      Serial.println( "next" );
      index=1;
    }else if (value.equals("7a")) { //向后快进
      Serial.println( "next" );
      index=2;
    }
    else if (value.equals("10")) { //向后快进
      Serial.println( "next" );
      index=3;
    }
    else if (value.equals("38")) { //向后快进
      Serial.println( "next" );
      index=4;
    }
    else if (value.equals("5a")) { //向后快进
      Serial.println( "next" );
      index=5;
    }
    else if (value.equals("42")) { //向后快进
      Serial.println( "next" );
      index=6;
    }
      Serial.println(value);
      
    IrReceiver.resume();
  }
}