Skip to content

Commit

Permalink
Basic filtering of adxl data
Browse files Browse the repository at this point in the history
  • Loading branch information
NickFoubert authored and Nick Foubert committed Aug 11, 2011
1 parent 1598941 commit 111250c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions datacollector/datacollector.pde
Expand Up @@ -8,6 +8,7 @@ const int X_PIN = 2;
const int Y_PIN = 3;
const int Z_PIN = 4;
const int DELAY_TIME = 1000;
const int BUFF_SIZE = 5;

const int mvu = 4.89;

Expand All @@ -19,12 +20,21 @@ float scale_factor = 0;
int vcc = 0;
int zero_g = 0;

float xbuffer[BUFF_SIZE];
float ybuffer[BUFF_SIZE];
float zbuffer[BUFF_SIZE];
int bp=0;

void setup() {
pinMode(GND_PIN, OUTPUT);
digitalWrite(GND_PIN, LOW);
pinMode(ST_PIN, OUTPUT);
digitalWrite(ST_PIN, LOW);
Serial.begin(9600);

for (int i=0; i<BUFF_SIZE; i++) {
xbuffer[i] = 0; ybuffer[i] = 0; zbuffer[i] = 0;
}
}

void loop() {
Expand All @@ -38,6 +48,19 @@ void loop() {
y = (analogRead(Y_PIN) - zero_g) * mvu * scale_factor;
z = (analogRead(Z_PIN) - zero_g) * mvu * scale_factor;

xbuffer[bp] = x;
ybuffer[bp] = y;
zbuffer[bp] = z;
bp = (bp + 1) % BUFF_SIZE;

x = 0; y = 0; z = 0;
for (int i=0; i<BUFF_SIZE; i++) {
x += xbuffer[i];
y += ybuffer[i];
z += zbuffer[i];
}
x /= BUFF_SIZE; y /= BUFF_SIZE; z /= BUFF_SIZE;

Serial.print(x);
Serial.print(',');
Serial.print(y);
Expand Down

0 comments on commit 111250c

Please sign in to comment.