View Single Post
  #17   Spotlight this post!  
Unread 05-03-2013, 13:26
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: Sensor "de-noising"

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
__________________

Don't PANIC!
S. P. A. M.

Last edited by EricS-Team180 : 05-03-2013 at 13:34.