PiSlingers library for AHRC competitions
Diff: IRObjDetector.cpp
- Revision:
- 1:695f4f4442d3
- Parent:
- 0:d4427d048a98
- Child:
- 2:a9351d7f92b4
--- a/IRObjDetector.cpp Sun Sep 09 22:28:06 2012 +0000 +++ b/IRObjDetector.cpp Fri Nov 02 03:00:29 2012 +0000 @@ -8,10 +8,19 @@ { int i; uint32_t max = 0; - int32_t tmp; + int32_t tmp = 0; //data[7] = ain.read_u16() >> 8; // Read the ambient level and store in last data slot. - data[7] = ain.read_u16(); // Read the ambient level and store in last data slot. + //data[7] = ain.read_u16(); // Read the ambient level and store in last data slot. + + // Average 4 readings of ambient. + tmp += ain.read_u16(); + tmp += ain.read_u16(); + tmp += ain.read_u16(); + tmp += ain.read_u16(); + + // Store ambient level in last data slot. + data[7] = tmp / 4; // Set the IR leds one at a time and read the reflection. for (i = 0; i < 7; i++) @@ -24,11 +33,22 @@ wait_us(DWELL_TIME); // Read ADC value and subtract off ambient. //tmp = (ain.read_u16() >> 8) - data[7]; - tmp = ain.read_u16() - data[7]; + //tmp = ain.read_u16() - data[7]; + // Average 4 readings + tmp = 0; + tmp += ain.read_u16(); + tmp += ain.read_u16(); + tmp += ain.read_u16(); + tmp += ain.read_u16(); + + // Take reading and subtract off ambient. + tmp = tmp / 4 - data[7]; + if (tmp < 0) data[i] = 0; else data[i] = tmp >> 8; + // Disable the selected LED. tlc5916.disable(); @@ -39,6 +59,7 @@ brightness = max; +#if 0 brightnessBins[currentBin++] = brightness; // Calculate running average over BRIGHTNESS_BINS bins. @@ -56,6 +77,9 @@ if (currentBin >= BRIGHTNESS_BINS) currentBin = 0; +#else + avgBrightness = brightness; +#endif } float