Advertisement
icorrelate

IR REMOTE LED

Apr 26th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. //Make sure you include IR Remote Library
  2. //https://github.com/z3t0/Arduino-IRremote
  3. #include <IRremote.h>
  4.  
  5. //Connect IR SENSOR in PIN 2
  6. const int RECV_PIN = 2;
  7. IRrecv irrecv(RECV_PIN);
  8. decode_results results;
  9.  
  10. //LED PINS
  11. int ledPin8 = 8;  
  12. int ledPin9 = 9;  
  13. int ledpin10 = 10;
  14.  
  15. //Dictate if Led is ON or OFF
  16. int state[] = {0,0,0};
  17.  
  18. void setup(){
  19.   Serial.begin(9600);
  20.   irrecv.enableIRIn();
  21.   irrecv.blink13(true);
  22.  
  23.   pinMode(ledPin8, OUTPUT);
  24.   pinMode(ledPin9, OUTPUT);
  25.   pinMode(ledpin10, OUTPUT);
  26. }
  27.  
  28. void loop(){
  29.   if (irrecv.decode(&results)){
  30.         long value = results.value;
  31.  
  32.         //Print IR Value in DEC, Check your serial monitor and change the numbers ... *16738455
  33.         Serial.println(value);
  34.  
  35.         switch(value){
  36.           case 16738455:
  37.             //Turn all LED Lights OFF
  38.             digitalWrite(ledPin8, LOW);
  39.             digitalWrite(ledPin9, LOW);
  40.             digitalWrite(ledpin10, LOW);
  41.           break;
  42.  
  43.           case 16750695:
  44.             //Turn all LED Lights ON
  45.             digitalWrite(ledPin8, HIGH);
  46.             digitalWrite(ledPin9, HIGH);
  47.             digitalWrite(ledpin10, HIGH);
  48.           break;
  49.  
  50.           case 16724175:
  51.  
  52.            
  53.             if(state[0] == 0){                  //Check if LED is OFF
  54.               digitalWrite(ledPin8, HIGH);      //Turn it ON
  55.               state[0] = 1;                     //Set State to 1 or ON
  56.             }else{
  57.               digitalWrite(ledPin8, LOW);       //Turn it OFF
  58.               state[0] = 0;                     //Set State to 0 or OFF
  59.             }
  60.           break;
  61.  
  62.           case 16718055:
  63.             if(state[1] == 0){
  64.               digitalWrite(ledPin9, HIGH);
  65.               state[1] = 1;
  66.             }else{
  67.               digitalWrite(ledPin9, LOW);
  68.               state[1] = 0;
  69.             }
  70.           break;
  71.  
  72.           case 16743045:
  73.             if(state[2] == 0){
  74.               digitalWrite(ledpin10, HIGH);
  75.               state[2] = 1;
  76.             }else{
  77.               digitalWrite(ledpin10, LOW);
  78.               state[2] = 0;
  79.             }
  80.           break;
  81.         }
  82.        
  83.         irrecv.resume();
  84.   }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement