/* * Door.cpp * * Created: 04.09.2014 22:06:23 * Author: netz */ #include "peripheral.h" #include uartclass Serial; stripeclass stripe; ledclass led; compclass comp; //intclass ir; // the maximum pulse we'll listen for - 65 milliseconds is a long time #define MAXPULSE 30000 // what our timing resolution should be, larger is better // as its more 'precise' - but too large and you wont get // accurate timing #define RESOLUTION 20 uint16_t volatile pulses[100][2]; // pair is high and low pulse uint8_t volatile currentpulse = 0; void printpulses(void) { Serial.println("\n\r\n\rReceived: \n\rOFF \tON"); for (uint8_t i = 0; i < currentpulse; i++) { Serial.printDec(pulses[i][0] * RESOLUTION); Serial.print(" "); Serial.printDec(pulses[i][1] * RESOLUTION); Serial.println(" "); } // print it in a 'array' format Serial.println("int IRsignal[] = {"); Serial.println("// OFF, ON (in 10's of microseconds)"); for (uint8_t i = 0; i < currentpulse-1; i++) { Serial.print("\t"); // tab Serial.printDec(pulses[i][0] * RESOLUTION / 10); Serial.print(", "); Serial.printDec(pulses[i][1] * RESOLUTION / 10); Serial.println(","); } Serial.print("\t"); // tab Serial.printDec(pulses[currentpulse-1][0] * RESOLUTION / 10); Serial.print(", "); Serial.printDec(pulses[currentpulse-1][1] * RESOLUTION / 10); Serial.println("};"); } void loop() { while(1) { uint16_t highpulse, lowpulse; // temporary storage timing highpulse = lowpulse = 0; // start out with no pulse length while (!(PIND & (1<= MAXPULSE) && (currentpulse != 0)) { printpulses(); return; } } pulses[currentpulse][1] = lowpulse; while (PIND & (1<= MAXPULSE) && (currentpulse != 0)) { printpulses(); return; } }// we didn't time out so lets stash the reading pulses[currentpulse][0] = highpulse; // we read one high-low pulse successfully, continue! currentpulse++; } } uint8_t read8bit() { uint8_t r = 0; for (uint8_t i=0;i<8;i++) { while (PIND & (1<