Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
  3. * An IR detector/demodulator must be connected to the input RECV_PIN.
  4. * Version 0.1 July, 2009
  5. * Copyright 2009 Ken Shirriff
  6. * http://arcfn.com
  7. */
  8. #include <IRremote.h>
  9. int RECV_PIN = 11;
  10. int RELAY_PIN = 4;
  11. IRrecv irrecv(RECV_PIN);
  12. decode_results results;
  13. // Dumps out the decode_results structure.
  14. // Call this after IRrecv::decode()
  15. // void * to work around compiler issue
  16. //void dump(void *v) {
  17. // decode_results *results = (decode_results *)v
  18. void dump(decode_results *results) {
  19. int count = results->rawlen;
  20. if (results->decode_type == UNKNOWN) {
  21. Serial.println("Could not decode message");
  22. }
  23. else {
  24. if (results->decode_type == NEC) {
  25. Serial.print("Decoded NEC: ");
  26. }
  27. else if (results->decode_type == SONY) {
  28. Serial.print("Decoded SONY: ");
  29. }
  30. else if (results->decode_type == RC5) {
  31. Serial.print("Decoded RC5: ");
  32. }
  33. else if (results->decode_type == RC6) {
  34. Serial.print("Decoded RC6: ");
  35. }
  36. Serial.print(results->value, HEX);
  37. Serial.print(" (");
  38. Serial.print(results->bits, DEC);
  39. Serial.println(" bits)");
  40. }
  41. Serial.print("Raw (");
  42. Serial.print(count, DEC);
  43. Serial.print("): ");
  44. for (int i = 0; i < count; i++) {
  45. if ((i % 2) == 1) {
  46. Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
  47. }
  48. else {
  49. Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
  50. }
  51. Serial.print(" ");
  52. }
  53. Serial.println("");
  54. }
  55. void setup()
  56. {
  57. pinMode(RELAY_PIN, OUTPUT);
  58. pinMode(13, OUTPUT);
  59. Serial.begin(9600);
  60. irrecv.enableIRIn(); // Start the receiver
  61. }
  62. int on = 0;
  63. unsigned long last = millis();
  64. void loop() {
  65. if (irrecv.decode(&results)) {
  66. // If it's been at least 1/4 second since the last
  67. // IR received, toggle the relay
  68. if (millis() - last > 250) {
  69. on = !on;
  70. digitalWrite(RELAY_PIN, on ? HIGH : LOW);
  71. digitalWrite(13, on ? HIGH : LOW);
  72. dump(&results);
  73. }
  74. last = millis();
  75. irrecv.resume(); // Receive the next value
  76. }
  77. }