Differences

This shows you the differences between two versions of the page.

Link to this comparison view

irdecode [2009/03/04 05:38] – created jonmashirdecode [2009/04/08 22:24] (current) jonmash
Line 1: Line 1:
 <code cpp> <code cpp>
 /******************************************************** /********************************************************
-*  Code to access the raw data coming from teh I2C thermo +*  Code to access the raw data coming from the IR receiver 
-*  pile array and dispay it on the console.+*  and display it on the screen. I used this code to generate 
 +*  the code that sends commands to the tv
 *  By: Jonathan Mash *  By: Jonathan Mash
 *  Date: Feb. 2009 *  Date: Feb. 2009
-*  Based on work by: Jon McPhalen (www.jonmcphalen.com)+*  Based on work by: Walter Anderson (wandrson@walteranderson.us)
 *********************************************************/ *********************************************************/
  
-int irPin = 2; +#include <avr/interrupt.h> 
-bool incoming_ir = false;+#include <avr/io.h>
  
-void setup() +#define TIMER_RESET  TCNT1 = 0 
-+#define SAMPLE_SIZE  150 
-  pinMode(irPin, INPUT); +#define DEGBUG 0
-  Serial.begin(9600); +
-  delay(25); +
-  attachInterrupt(0, IRISR, FALLING); +
-}+
  
-void IRISR() +int IRpin = 2; 
-+unsigned int TimerValue[SAMPLE_SIZE]; 
-    incoming_ir true;+char direction[SAMPLE_SIZE]; 
 +byte change_count; 
 +long time; 
 +int value; 
 +void setup() { 
 +  Serial.begin(115200); 
 +  Serial.println("Analyze IR Remote"); 
 +  TCCR1A 0x00;          // COM1A1=0, COM1A0=0 => Disconnect Pin OC1 from Timer/Counter 1 -- PWM11=0,PWM10=0 => PWM Operation disabled 
 +  // ICNC1=0 => Capture Noise Canceler disabled -- ICES1=0 => Input Capture Edge Select (not used) -- CTC1=0 => Clear Timer/Counter 1 on Compare/Match 
 +  // CS12=0 CS11=1 CS10=1 => Set prescaler to clock/64 
 +  TCCR1B = 0x03;          // 16MHz clock with prescaler means TCNT1 increments every 4uS 
 +  // ICIE1=0 => Timer/Counter 1, Input Capture Interrupt Enable -- OCIE1A=0 => Output Compare A Match Interrupt Enable -- OCIE1B=0 => Output Compare B Match Interrupt Enable 
 +  // TOIE1=0 => Timer 1 Overflow Interrupt Enable 
 +  TIMSK1 = 0x00;           
 +  pinMode(IRpin, INPUT);
 } }
  
 void loop() void loop()
 { {
-  int key+  Serial.println("Waiting...")
- +  change_count = 0; 
-  if(incoming_ir == true+  while(digitalRead(IRpin) == HIGH) {}                                  
-  { +  TIMER_RESET; 
-    key getSircs();+  TimerValue[change_count] = TCNT1; 
 +  direction[change_count++] = '0'; 
 +  while (change_count < SAMPLE_SIZE) { 
 +    if (direction[change_count-1] == '0'
 +      while(digitalRead(IRpin) == LOW) {} 
 +      TimerValue[change_count] = TCNT1; 
 +      direction[change_count++] = '1'; 
 +    } else { 
 +      while(digitalRead(IRpin) == HIGH) {} 
 +      TimerValue[change_count] = TCNT1; 
 +      direction[change_count++] = '0'; 
 +    } 
 +  
 +  //Serial.println("Bit stream detected!"); 
 +  change_count = 0; 
 +  time = (long) TimerValue[change_count] * 4; 
 +  change_count++; 
 +  while (change_count < SAMPLE_SIZE) 
 +    time = (longTimerValue[change_count] * 4;
          
-    if(key == 0x1D01+    if(direction[change_count-1] == '0' && direction[change_count] == '1') 
-      Serial.println("POWER"); +    { 
-    else if(key == 0x701+      Serial.print("\t//"); 
-      Serial.println("Volume UP"); +      Serial.print((int)change_count); 
-    else if(key == 0x901+      Serial.print("\t"); 
-      Serial.println("Volume DN"); +      Serial.print("HIGH\t"); 
-    else +      Serial.print("\t"); 
-      Serial.println("Unknown Command");+      Serial.println(time - (long)TimerValue[change_count-1] * 4); 
 +      Serial.print("\toscillationWrite(led_pin, "); 
 +      Serial.print(time - (long)TimerValue[change_count-1] * 4); 
 +      Serial.println(");"); 
 +    } 
 +    else if(direction[change_count-1] == '1' && direction[change_count] == '0') 
 +    { 
 +      Serial.print("\t//"); 
 +      Serial.print((int)change_count); 
 +      Serial.print("\t"); 
 +      Serial.print("LOW\t"); 
 +      Serial.print("\t"); 
 +      Serial.println(time - (long)TimerValue[change_count-1] * 4); 
 +      Serial.print("\tdelayMicroseconds("); 
 +      Serial.print(time - (long)TimerValue[change_count-1] * 4); 
 +      Serial.println(");"); 
 +    } 
 +    change_count++;  
   }   }
- +  value=0; 
-  Serial.println(analogRead(0)); +  delay(100);
- +
-  delay(50);+
 } }
  
-int getSircs() { 
-  int duration; 
-  int irCode; 
-  int mask; 
-   
-  incoming_ir = false; 
-  // wait for start bit 
-  do { 
-    duration = pulseIn(irPin, HIGH); 
-  } while (duration < 2000); 
- 
-  // get 12-bit SIRCS code 
-  irCode = 0; // clear ir code 
-  mask = 1; // set mask to bit 0 
-  for (int idx = 0; idx < 16; idx++) {         // get all 12 bits 
-    duration = pulseIn(irPin, HIGH);         // measure the bit pulse 
-    if (duration >= 600) // 1 bit? 
- irCode |= mask; // yes, update ir code 
-    mask <<= 1; // shift mask to next bit 
-  } 
-  return irCode; 
-} 
 </code> </code>
irdecode.1236145131.txt.gz · Last modified: by jonmash
Back to top
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0