apl-mhd

Light on off 8

Jan 4th, 2021
697
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <IRremote.h>
  2.  
  3. #define first_key 16724175
  4. #define second_key 16718055
  5. #define third_key 16743045
  6. #define fourth_key 16716015
  7. int receiver_pin = 11;  
  8.  
  9. int first_led_pin = 13;
  10. int second_led_pin = 12;
  11. int third_led_pin = 10;
  12. int fourth_led_pin = 7;
  13.  
  14. int led[] = {0,0,0,0};
  15. IRrecv receiver(receiver_pin);
  16. decode_results output;
  17.  
  18. void setup()
  19. {
  20.   Serial.begin(9600);
  21.   receiver.enableIRIn();  
  22.   pinMode(first_led_pin, OUTPUT);
  23.   pinMode(second_led_pin, OUTPUT);
  24.   pinMode(third_led_pin, OUTPUT);
  25.   pinMode(fourth_led_pin, OUTPUT);
  26.   }
  27.  
  28. void loop() {
  29.   if (receiver.decode(&output)) {
  30.     unsigned int value = output.value;
  31.     switch(value) {
  32.        case first_key:    
  33.          if(led[1] == 1) {      
  34.             digitalWrite(first_led_pin, LOW);
  35.             led[1] = 0;          
  36.          } else {                      
  37.              digitalWrite(first_led_pin, HIGH);
  38.              led[1] = 1;          
  39.          }
  40.           break;
  41.        case second_key:
  42.      
  43.          if(led[2] == 1) {
  44.             digitalWrite(second_led_pin, LOW);
  45.             led[2] = 0;
  46.          } else {
  47.              digitalWrite(second_led_pin, HIGH);
  48.              led[2] = 1;
  49.          }
  50.           break;
  51.        case third_key:
  52.      
  53.          if(led[3] == 1) {
  54.             digitalWrite(third_led_pin, LOW);
  55.             led[3] = 0;
  56.          } else {
  57.              digitalWrite(third_led_pin, HIGH);
  58.              led[3] = 1;
  59.          }
  60.           break;  
  61.           case fourth_key:
  62.      
  63.          if(led[4] == 1) {      
  64.             digitalWrite(fourth_led_pin, LOW);
  65.             led[4] = 0;          
  66.          } else {                      
  67.              digitalWrite(fourth_led_pin, HIGH);
  68.              led[4] = 1;          
  69.          }
  70.           break;        
  71.     }
  72.     Serial.println(value);
  73.     receiver.resume();
  74.   }
  75. }
RAW Paste Data