NapsterMP3

IR Receber sinais

Jul 3rd, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. // CODIGO EM CC MODIFICADO POR NERDKINGTEAM
  2. // VISITE: nerdking.com.br
  3. // youtube.com/nerdkingteam
  4.  
  5. #define IRpin_PIN PIND
  6. #define IRpin 2
  7.  
  8. // the maximum pulse we'll listen for - 65 milliseconds is a long time
  9. #define MAXPULSE 65000
  10.  
  11. // what our timing resolution should be, larger is better
  12. // as its more 'precise' - but too large and you wont get
  13. // accurate timing
  14. #define RESOLUTION 20
  15.  
  16. // we will store up to 100 pulse pairs (this is -a lot-)
  17. uint16_t pulses[100][2]; // pair is high and low pulse
  18. uint8_t currentpulse = 0; // index for pulses we're storing
  19.  
  20. void setup(void) {
  21. Serial.begin(9600);
  22. Serial.println("Ready to decode IR!");
  23. }
  24.  
  25. void loop(void) {
  26. uint16_t highpulse, lowpulse; // temporary storage timing
  27. highpulse = lowpulse = 0; // start out with no pulse length
  28.  
  29.  
  30. // while (digitalRead(IRpin)) { // this is too slow!
  31. while (IRpin_PIN & _BV(IRpin)) {
  32. // pin is still HIGH
  33.  
  34. // count off another few microseconds
  35. highpulse++;
  36. delayMicroseconds(RESOLUTION);
  37.  
  38. // If the pulse is too long, we 'timed out' - either nothing
  39. // was received or the code is finished, so print what
  40. // we've grabbed so far, and then reset
  41. if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
  42. printpulses();
  43. currentpulse=0;
  44. return;
  45. }
  46. }
  47. // we didn't time out so lets stash the reading
  48. pulses[currentpulse][0] = highpulse;
  49.  
  50. // same as above
  51. while (! (IRpin_PIN & _BV(IRpin))) {
  52. // pin is still LOW
  53. lowpulse++;
  54. delayMicroseconds(RESOLUTION);
  55. if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
  56. printpulses();
  57. currentpulse=0;
  58. return;
  59. }
  60. }
  61. pulses[currentpulse][1] = lowpulse;
  62.  
  63. // we read one high-low pulse successfully, continue!
  64. currentpulse++;
  65. }
  66.  
  67. void printpulses(void) {
  68. Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  69. for (uint8_t i = 0; i < currentpulse; i++) {
  70. Serial.print("delayMicroseconds(");
  71. Serial.print(pulses[i][0] * RESOLUTION, DEC);
  72. Serial.print(");\n");
  73. Serial.print("pulseIR(");
  74. Serial.print(pulses[i][1] * RESOLUTION, DEC);
  75. Serial.print(");\n");
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment