Advertisement
Guest User

Untitled

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