/* Analog Bandpass Filter
* Jeff Gray - 2008
* ------------------
* Checks average, and only sends events if the new
* data is within a certain gate of the average
*/
int average[100];
byte counter = 0;
// amount on either side of average where values will be sent
int gate = 50;
void setup() {
Serial.begin(19200);
}
void loop() {
// read the value from the sensor
int inAn = analogRead(0);
// set in rolling buffer
average[counter] = inAn;
// average by buffer
byte c;
int total = 0;
for(c = 0;c<100;c++){
total += average[c];
}
int averaged = total / 100;
// increment position in rolling buffer
counter = (counter + 1) % 100;
// set gate for valid data
if(inAn <= (averaged + gate) && inAn >= (averaged - gate) ){
Serial.println(inAn);
}
}