/********************************************************
*  Code to relay the data from one PIR sensor to the PC
*  using a simple low-pass filter (weighted average).
*  By: Jonathan Mash
*  Date: Feb. 2009
*********************************************************/
 
#define PIR_HIST 5
int PIR_idx;
int PIR_one[PIR_HIST];
 
 
void setup()
{
  Serial.begin(9600);
 
  PIR_idx = 0;
}
 
 
void loop()
{
  Record();
 
  Serial.println(PIR_one[PIR_idx]);
 
  PIR_idx++;
  if(PIR_idx == PIR_HIST)
    PIR_idx = 0;
  delay(50);
}
 
void Record()
{
  int i = PIR_idx;
 
  PIR_one[PIR_idx] = (int)floor(analogRead(0)*0.75);
 
  if(i == 0)
    i = PIR_HIST-1;
  else
    i = i-1;
  PIR_one[PIR_idx] += (int)floor(PIR_one[i]*0.125);
 
  if(i == 0)
    i = PIR_HIST-1;
  else
    i = i-1;
  PIR_one[PIR_idx] += (int)floor(PIR_one[i]*0.1);
 
  if(i == 0)
    i = PIR_HIST-1;
  else
    i = i-1;
  PIR_one[PIR_idx] += (int)floor(PIR_one[i]*0.025); 
}
onepir.txt · Last modified: 2009/03/04 05:33 by jonmash
Back to top
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0