Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1.  
  2. #include <IRremote.h>
  3.  
  4. int RECV_PIN = 11;
  5.  
  6. IRrecv irrecv(RECV_PIN);
  7.  
  8. decode_results results;
  9.  
  10. void setup()
  11. {
  12. Serial.begin(9600);
  13. irrecv.enableIRIn(); // Start the receiver
  14. }
  15.  
  16. // Dumps out the decode_results structure.
  17. // Call this after IRrecv::decode()
  18. // void * to work around compiler issue
  19. //void dump(void *v) {
  20. // decode_results *results = (decode_results *)v
  21. void dump(decode_results *results) {
  22. int count = results->rawlen;
  23. if (results->decode_type == UNKNOWN) {
  24. Serial.print("Unknown encoding: ");
  25. }
  26. else if (results->decode_type == NEC) {
  27. Serial.print("Decoded NEC: ");
  28. }
  29. else if (results->decode_type == SONY) {
  30. Serial.print("Decoded SONY: ");
  31. }
  32. else if (results->decode_type == RC5) {
  33. Serial.print("Decoded RC5: ");
  34. }
  35. else if (results->decode_type == RC6) {
  36. Serial.print("Decoded RC6: ");
  37. }
  38. else if (results->decode_type == SAMSUNG) {
  39. Serial.print("Decoded SAMSUNG: ");
  40. }
  41. else if (results->decode_type == JVC) {
  42. Serial.print("Decoded JVC: ");
  43. }
  44. else if (results->decode_type == PANASONIC) {
  45. Serial.print("Decoded Panasonic: ");
  46. }
  47. //(results->value, HEX);
  48. switch (result->value) {
  49. case 16724175:
  50. Serial.print ("1");
  51. break;
  52. case 16718055:
  53. Serial.print ("2");
  54. break;
  55. case 16743045:
  56. Serial.print ("3");
  57. break;
  58. default:
  59. Serial.print ("hai premuto un tasto che io non riconosco");
  60. break;
  61. }
  62. Serial.print("(");
  63. Serial.print(results->bits, DEC);
  64. Serial.println(" bits)");
  65. Serial.print("#define Something_DEC ");
  66. Serial.println(results->value, DEC);
  67. Serial.print("#define Something_HEX ");
  68. Serial.println(results->value, HEX);
  69. /* Serial.print("Raw (");
  70. Serial.print(count, DEC);
  71. Serial.print("): ");
  72. for (int i = 0; i < count; i++) {
  73. if ((i % 2) == 1) {
  74. Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
  75. }
  76. else {
  77. Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
  78. }
  79. Serial.print(" ");
  80. }*/
  81. Serial.println("");
  82. }
  83.  
  84. void loop() {
  85. if (irrecv.decode(&results)) {
  86. dump(&results);
  87. irrecv.resume(); // Receive the next value
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement