Reputation: 29
How to Create Pedometer in WP7 ??
i need create one Pedometer to study
But i don't how to do Pedometer ?
M = Math.Sqrt(args.X * args.X + args.Y * args.Y + args.Z * args.Z);
if (Tec == true)
{
if (M >= 2)
{
if (Magnitude == true)
{
counter = counter + 1;
Magnitude = false;
}
}
else
{
Magnitude = true;
}
}
Upvotes: 1
Views: 4017
Reputation: 637
This works for me:
private bool hasChanged;
private int counter;
private void checkIsMouvement(SensorReadingEventArgs<AccelerometerReading> e)
{
float x = e.get_SensorReading().get_Acceleration().X;
float y = e.get_SensorReading().get_Acceleration().Y;
float z = e.get_SensorReading().get_Acceleration().Z;
double oldValue = ((x_old * x) + (y_old * y)) + (z_old * z);
double oldValueSqrT = Math.Abs(Math.Sqrt((double) (((x_old * x_old) + (y_old * y_old)) + (z_old * z_old))));
double newValue = Math.Abs(Math.Sqrt((double) (((x * x) + (y * y)) + (z * z))));
oldValue /= oldValueSqrt * newValue;
if ((oldValue <= 0.994) && (oldValue > 0.9))
{
if (!hasChanged)
{
hasChanged = true;
counter++; //here the counter
}
else
{
hasChanged = false;
}
}
x_old = x;
y_old = y;
z_old = z;
}
Upvotes: 4