aidanozohor1810

Untitled

Dec 14th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <IRremote.h>
  2. const int receiver = 5;
  3. IRrecv irrecv(receiver);
  4. decode_results results;
  5.  
  6. const byte releuPin = 6;
  7. volatile byte stat = 0;
  8. const int buzzerPin = 4;
  9.  
  10. void setup()
  11. { irrecv.enableIRIn();
  12.   pinMode(releuPin, OUTPUT);
  13.   pinMode(buzzerPin, OUTPUT);
  14. }
  15.  
  16. void playTone(int tone, int duration) {
  17.  for (long i = 0; i < duration * 1000L; i += tone * 2) {
  18.  digitalWrite(buzzerPin, HIGH);
  19.  delayMicroseconds(tone);
  20.  digitalWrite(buzzerPin, LOW);
  21.  delayMicroseconds(tone);
  22.  }
  23. }
  24.  
  25. void loop() {
  26.   if (stat) {
  27.     digitalWrite(releuPin, HIGH);
  28.     delay(1000);
  29.     digitalWrite(releuPin, LOW);
  30.     delay(1000);
  31.   }
  32.   if (irrecv.decode(&results))
  33.   {
  34.     if (results.value == 0x20DF807F)
  35.  
  36.       digitalWrite(releuPin, HIGH);
  37.  
  38.     else
  39.  
  40.     if(results.value == 0x20DF609F)
  41.  
  42.        playTone(2000, 500);
  43.  
  44.     else
  45.  
  46.     if(results.value == 0x20DF906F)
  47.  
  48.       digitalWrite(releuPin, LOW);
  49.  
  50.     else
  51.     if(results.value == 0x20DF50AF)
  52.     {
  53.       digitalWrite(releuPin, HIGH);
  54.       playTone(2000, 500);
  55.     }
  56.     else if(results.value == 0x20DFD02F)
  57.     {
  58.       digitalWrite(releuPin, LOW);
  59.       playTone(2000, 500);
  60.     }
  61.     irrecv.resume(); // receive the next value
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment