#include //all IR codes of the remote #define MENU 0x4FB906F #define ZOOM 0x4FB9867 #define FREEZE 0x4FBE817 #define MODE 0x4FB02FD #define ENTER 0x4FB8877 #define ARROWUP 0x4FBF807 #define ARROWDOWN 0x4FB6897 #define ARROWRIGHT 0x4FBA857 #define ARROWLEFT 0x4FBD827 #define MODE1 0x4FB32CD #define MODE2 0x4FB20DF #define MODE3 0x4FB00FF #define MODE4 0x4FB50AF #define MODE5 0x4FB7887 #define MODE6 0x4FB708F #define MODE7 0x4FB58A7 #define CH1 0x4FB38C7 #define CH2 0x4FB28D7 #define CH3 0x4FBF00F #define CH4 0x4FB30CF //objekt for IR-Signal IRsend irsend; //Pin for RC-Control int rcPin = 4; //compare pulse time for RC-On and RC-Off int rcOn = 1150; //variable for edge detection int rcEdge=0; int state=0; //returns 1 if rising edge and 2 if falling edge int rcControl(){ int pulse=pulseIn(rcPin, HIGH); if(!rcEdge&&pulse700){ rcEdge=1; return 1; } if(rcEdge&&pulse>rcOn){ rcEdge=0; return 2; } return 0; } //swap the two PIP channels void swapPIP(){ irsend.sendNEC(MENU, 56); delay(100); irsend.sendNEC(ARROWUP, 56); delay(100); irsend.sendNEC(ARROWUP, 56); delay(100); irsend.sendNEC(ARROWUP, 56); delay(100); irsend.sendNEC(MENU, 56); delay(100); irsend.sendNEC(MENU, 56); delay(100); } //swap the two PIP channels back void swapPIPback(){ irsend.sendNEC(MENU, 56); delay(100); irsend.sendNEC(ARROWDOWN, 56); delay(100); irsend.sendNEC(ARROWDOWN, 56); delay(100); irsend.sendNEC(ARROWDOWN, 56); delay(100); irsend.sendNEC(MENU, 56); delay(100); irsend.sendNEC(MENU, 56); delay(100); } //switch PIP-Mode ON void pipON(){ delay(100); irsend.sendNEC(MODE5, 56); } //switch PIP-Mode OFF/switch to Channel 1 void pipOFF(){ delay(100); irsend.sendNEC(CH1, 56); } //switch to Channel 2 void switchToCH2(){ delay(100); irsend.sendNEC(CH2, 56); } void setup() { delay(1500); //RC-Pin as input pinMode(rcPin, INPUT); //init PIP pipOFF(); //pipON(); } void loop() { int rc=rcControl(); //action when RC Switch is turned ON if(rc==1){ //do what you want } //action when RC Switch is turned OFF if(rc==2){ switch(state){ case 0: pipON(); state=1; break; case 1: switchToCH2(); state=2; break; case 2: pipOFF(); state=0; break; } } }