that_one_nigga_you_k

zdm,hfba

Oct 26th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. /*
  2. Author: AnalysIR
  3. Revision: 1.0
  4.  
  5. This code is provided to overcome an issue with Arduino IR libraries
  6. It allows you to capture raw timings for signals longer than 255 marks & spaces.
  7. Typical use case is for long Air conditioner signals.
  8.  
  9. You can use the output to plug back into IRremote, to resend the signal.
  10.  
  11. This Software was written by AnalysIR.
  12.  
  13. Usage: Free to use, subject to conditions posted on blog below.
  14. Please credit AnalysIR and provide a link to our website/blog, where possible.
  15.  
  16. Copyright AnalysIR 2014
  17.  
  18. Please refer to the blog posting for conditions associated with use.
  19. http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/
  20.  
  21. Connections:
  22. IR Receiver      Arduino
  23. V+          ->  +5v
  24. GND          ->  GND
  25. Signal Out   ->  Digital Pin 2
  26. (If using a 3V Arduino, you may connect V+ to +3V)
  27. */
  28.  
  29. #define LEDPIN 13
  30. //you may increase this value on Arduinos with greater than 2k SRAM
  31. #define maxLen 800
  32.  
  33. volatile  unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
  34. volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR
  35.  
  36. void setup() {
  37.   Serial.begin(115200); //change BAUD rate as required
  38.   attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
  39. }
  40.  
  41. void loop() {
  42.   // put your main code here, to run repeatedly:
  43.  
  44.   Serial.println(F("Press the button on the remote now - once only"));
  45.   delay(5000); // pause 5 secs
  46.   if (x) { //if a signal is captured
  47.     digitalWrite(LEDPIN, HIGH);//visual indicator that signal received
  48.     Serial.println();
  49.     Serial.print(F("Raw: (")); //dump raw header format - for library
  50.     Serial.print((x - 1));
  51.     Serial.print(F(") "));
  52.     detachInterrupt(0);//stop interrupts & capture until finshed here
  53.     for (int i = 1; i < x; i++) { //now dump the times
  54.       if (!(i & 0x1)) Serial.print(F("-"));
  55.       Serial.print(irBuffer[i] - irBuffer[i - 1]);
  56.       Serial.print(F(", "));
  57.     }
  58.     x = 0;
  59.     Serial.println();
  60.     Serial.println();
  61.     digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time
  62.     attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
  63.   }
  64.  
  65. }
  66.  
  67. void rxIR_Interrupt_Handler() {
  68.   if (x > maxLen) return; //ignore if irBuffer is already full
  69.   irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions
  70.  
  71. }
Add Comment
Please, Sign In to add comment