While Kevin's approach is far more elegant, this might work for you in a pinch:
Code:
/* some set-up */
#include <stdio.h>
#define true 1
#define false !true
typedef char boolean;
/* a program to run the stuff */
int main (void)
{
static int array[5] = {0,0,0,0,0};
static int counter = 0;
boolean persistence;
boolean digitalInput;
int i;
/* run the persistance checker in a loop */
for (i=0; i<10; i++)
{
/* put in some false then put in some true */
if(i>4)
digitalInput = true;
else
digitalInput = false;
/* check on the input and fill the
* persistence array with the result
*/
if( digitalInput)
array[counter] = 1;
else
array[counter] = 0;
/* keep tabs on the array index */
counter++;
if(counter > 4)
counter = 0;
/* now AND the entire array and show the result */
persistence = array[0] && array[1] && array[2] && array[3] && array[4];
printf(" perist = %d \n",persistence);
}
}
When the array fills and remains filled, you get true, otherwise it's false
...ugly but it could work
Eric