Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1.  
  2. #include <IRremote.h>
  3.  
  4. int RECV_PIN = A3;
  5. IRrecv irrecv(RECV_PIN);
  6. decode_results results;
  7. IRsend irsend;
  8. int IRLED = 3;
  9. int buttonPin = 8;
  10. int buttonState = 0;
  11.  
  12.  
  13. void setup()
  14. {
  15.   Serial.begin(9600);
  16.   irrecv.enableIRIn(); // Start the receiver
  17.   pinMode(IRLED, OUTPUT);
  18.   pinMode(buttonPin, INPUT);
  19. }
  20.  
  21.  
  22. //Infinite loop
  23. void loop()
  24. { buttonState = digitalRead(buttonPin);
  25.   if (buttonPin == HIGH) {
  26.     irsend.sendNEC(0x61A0F00F, 32); // TV power code
  27.     delay(100);
  28.   }
  29.  
  30.  {
  31.     if (irrecv.decode(&results)) {
  32.       Serial.println(results.value, DEC);}
  33.       dump(&results);
  34.       irrecv.resume(); // Receive the next value
  35.     }
  36.   }
  37.  
  38.   //Dumps the result and prints the numeric received dada and type of remote
  39.   void dump(decode_results * results) {
  40.     // Dumps out the decode_results structure.
  41.     // Call this after IRrecv::decode()
  42.     int count = results->rawlen;
  43.     if (results->decode_type == UNKNOWN) {
  44.       Serial.print("Unknown encoding: ");
  45.     }
  46.     else if (results->decode_type == NEC) {
  47.       Serial.print("Decoded NEC: ");
  48.     }
  49.     else if (results->decode_type == SONY) {
  50.       Serial.print("Decoded SONY: ");
  51.     }
  52.     else if (results->decode_type == RC5) {
  53.       Serial.print("Decoded RC5: ");
  54.     }
  55.     else if (results->decode_type == RC6) {
  56.       Serial.print("Decoded RC6: ");
  57.     }
  58.     else if (results->decode_type == PANASONIC) {
  59.       Serial.print("Decoded PANASONIC - Address: ");
  60.       Serial.print(results->address, HEX);
  61.       Serial.print(" Value: ");
  62.     }
  63.     else if (results->decode_type == LG) {
  64.       Serial.print("Decoded LG: ");
  65.     }
  66.     else if (results->decode_type == JVC) {
  67.       Serial.print("Decoded JVC: ");
  68.     }
  69.     else if (results->decode_type == AIWA_RC_T501) {
  70.       Serial.print("Decoded AIWA RC T501: ");
  71.     }
  72.     else if (results->decode_type == WHYNTER) {
  73.       Serial.print("Decoded Whynter: ");
  74.     }
  75.     Serial.print(results->value, HEX);
  76.     Serial.print(" (");
  77.     Serial.print(results->bits, DEC);
  78.     Serial.println(" bits)");
  79.     Serial.print("Raw (");
  80.     Serial.print(count, DEC);
  81.     Serial.print("): ");
  82.  
  83.     for (int i = 1; i < count; i++) {
  84.       if (i & 1) {
  85.         Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
  86.       }
  87.       else {
  88.         Serial.write('-');
  89.         Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
  90.       }
  91.       Serial.print(" ");
  92.     }
  93.     Serial.println();
  94.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement