Hmmm....neat problem. Thinking out loud:
#define NUM_VALUES 4 // How many values should be the same
#define VALTYPE uint8_t // Replace with whatever type your values are
VALTYPE values[NUM_VALUES];
uint8_t valIndex = 0;
void addValue(VALTYPE value) {
values[valIndex++] = value;
if (valIndex == NUM_VALUES) valIndex = 0;
}
uint8_t checkValues(void)
{
uint8_t i;
for (i=0; i < NUM_VALUES-1; i++) {
if (values[i] != values[i+1]) return 0;
}
return 1;
}
In your main loop you would call addValue() whenever you got a new sensor reading, and checkValues() when you wanted to see if the last NUM_VALUES values were all the same.
--
The
Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons