how to integrate the velocity equation into a code

My coding group is trying to code something that counts how many times the velocity of an accelerometer reaches 0. And then code a buzzer to sound when it reaches a specific number. We know we need to imbed the equation for velocity in our loop and have coded the buzzer but are trouble shooting the counting mechanism. If anyone knows or has done something similar to this, help would be very appreciated!

metro_thingy.zip (7.2 KB)

Something like this, maybe :) :

***pseudo code***

int currentAcc, lastAcc, counter;

void loop()
{
  get(currentAcc); // read current value
  if(currentAcc != lastAcc) // if different
  {
    if(currentAcc == 0)
    {
      counter++; // add 1
      lastAcc = currentAcc; // make same
    }
    if(counter >= 10) // if 10 or more
      BUZZ
  }
}

Welcome Heather. Seems you got the short straw and had to face the Forum. It's not as bad as what you may have heard. A bit intimidating perhaps at first, but with good intentions. Why not show us the code you're working with now and we can take it from there. To avoid the first attack of the Lions, best you read the post at the top of the Forum, the one that says "Read this before posting a programming question ..." (catchy, no?).

So, you need to count the number of times that the velocity becomes zero after not having been zero before.

You might want a little hysteresis in this, too.