My code in arduino, volume and power functionalities.
Code: #include #include // Define sensor pinconst int RECV_PIN = 4; byte incomingByte; byte msgTurnOff[] ={0xA6,0x01,0x00,0x00,0x00,0x04,0x01,0x18,0x01,0xBB}; //10 byte msgTurnOn[] ={0xA6,0x01,0x00,0x00,0x00,0x04,0x01,0x18,0x02,0xB8}; //10 byte getVolume[] ={0xA6,0x01,0x00,0x00,0x00,0x03,0x01,0x45,0xE0}; //9 byte setVolume[] ={0xA6,0x01,0x00,0x00,0x00,0x04,0x01,0x44,0x01,0xE7}; //10 byte inputSourceHDMI [2][13] ={{0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0xAC,0x06,0x02,0x00,0x00,0x09},//hdmi {0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0xAC,0x06,0x03,0x00,0x00,0x08}};//MHL-hdmi byte PIP [2][13]= {{0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0x3C,0x00,0x00,0x00,0x00,0x9D},//off {0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0x3C,0x01,0x00,0x00,0x00,0x9C}};//on byte PIPPosition [4][13]= {{0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0x3C,0x01,0x00,0x00,0x00,0x9C},//bottom left {0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0x3C,0x01,0x01,0x00,0x00,0x9D},//top left {0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0x3C,0x01,0x02,0x00,0x00,0x9E},//topright {0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0x3C,0x01,0x03,0x00,0x00,0x9F} //bottom roght }; byte PIPSource [2][13]= {{0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0x84,0xFD,0x02,0x00,0x00,0xDA},//hdmi {0xA6,0x01,0x00,0x00,0x00,0x07,0x01,0x84,0xFD,0x03,0x00,0x00,0xDB}};//mhd-hdmi int currentInputSource = 0; int PIPstate = 0; int PIPPositionState=0; int PIPSourceState=0; bool powerState=true; int volume; int eIndex; #define MAX_MILLIS_TO_WAIT 1000 //or whateverunsigned long starttime;byte read_bytes[9];// Define IR Receiver and Results ObjectsIRrecv irrecv(RECV_PIN);decode_results results;SoftwareSerial gtSerial(7, 8); // Arduino RX, Arduino TXvoid setup(){ // Serial Monitor @ 9600 baud Serial.begin(9600,SERIAL_8N1); gtSerial.begin(9600); // Enable the IR Receiver irrecv.enableIRIn(); // initialize digital pin LED_BUILTIN as an output. //pinMode(LED_BUILTIN, OUTPUT); gtSerial.write(getVolume, sizeof(getVolume)); while ( (gtSerial.available() 0) { // read the incoming byte: incomingByte = Serial.read(); // say what you got: // Serial.print(incomingByte, HEX); gtSerial.write(incomingByte); } if (gtSerial.available() > 0) { // read the incoming byte: incomingByte = gtSerial.read(); // say what you got: // Serial.print(incomingByte, HEX); Serial.write(incomingByte); }*/ if (irrecv.decode(&results)){ // Print Code in HEX Serial.println(results.value, HEX); switch(results.value){ case 0x34347887: // power // Turn on LED for 2 Seconds // digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) //gtSerial.write(msg, sizeof(msg)); if(powerState){ msgTurnOff[10 - 1] = CheckSum(msgTurnOff,10); gtSerial.write(msgTurnOff, sizeof(msgTurnOff)); powerState=false; }else{ msgTurnOn[10 - 1] = CheckSum(msgTurnOn,10); gtSerial.write(msgTurnOn, sizeof(msgTurnOn)); powerState=true; } delay(500); // wait for a second //digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW break; case 0x3434E817: // volume up // Turn on LED for 2 Seconds // digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) if(eIndex!=-1){ // Serial.println(e); if(volume9) volume=volume-10; setVolume[8]=(byte)volume; Serial.println(volume); setVolume[10 - 1] = CheckSum(setVolume,10); gtSerial.write(setVolume, sizeof(setVolume)); delay(500); // wait for a second // digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW break; case 0x343459A6: // inputsource // Turn on LED for 2 Seconds // digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) gtSerial.write(inputSourceHDMI[currentInputSource], sizeof(inputSourceHDMI[currentInputSource])); if(currentInputSource==0) currentInputSource=1; else currentInputSource=0; delay(500); // wait for a second // digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW break; case 0x3434D52A: // PIP On Off gtSerial.write(PIP[PIPstate], sizeof(PIP[PIPstate])); PIPstate ; if(PIPstate==2) PIPstate=0; delay(500); // wait for a second break; case 0x343445BA: // PIP Position gtSerial.write(PIPPosition[PIPPositionState], sizeof(PIPPosition[PIPPositionState])); PIPPositionState ; if(PIPPositionState==4) PIPPositionState=0; delay(500); // wait for a second break; case 0x3434FD02: // PIP source gtSerial.write(PIPSource[PIPSourceState], sizeof(PIPSource[PIPSourceState])); PIPSourceState ; if(PIPSourceState==2) PIPSourceState=0; delay(500); // wait for a second break; } irrecv.resume(); }} |