This is an old revision of the document!
<code cpp> /******************************************************** * Code to access the raw data coming from teh I2C thermo * pile array and dispay it on the console. * By: Jonathan Mash * Date: Feb. 2009 * Based on work by: Jon McPhalen (www.jonmcphalen.com) *********************************************************/ int irPin = 2; bool incoming_ir = false; void setup() { pinMode(irPin, INPUT); Serial.begin(9600); delay(25); attachInterrupt(0, IRISR, FALLING); } void IRISR() { incoming_ir = true; } void loop() { int key; if(incoming_ir == true) { key = getSircs(); if(key == 0x1D01) Serial.println("POWER"); else if(key == 0x701) Serial.println("Volume UP"); else if(key == 0x901) Serial.println("Volume DN"); else Serial.println("Unknown Command"); } Serial.println(analogRead(0)); 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>
Back to top