Please help me, friends. I have finished making a steps counter. My problem now is that my timer starts with the accelerometer, but it doesn't stop when the accelerometer stops.(Pedometer is an application where the user can count his\her steps. With this information, the user can count his total calories consumed, and the total elapsed time.) The problem is that my timer is not working properly. Please help me out.
here is code
if ( fabsf(acceleration.y) > progressAsInt ) {
steps++;
timer1 = [NSTimer scheduledTimerWithTimeInterval:(.01) target:self selector:@selector(timepassed) userInfo:nil repeats:YES];
NSString *stepcount = [NSString stringWithFormat:@"%d", steps];
[stepstaken setText:stepcount];
//it's for the MPH speed calculation formula changes can be happen
/*formula mph= miles/hour
0.5miles
10minutes = 10/60 hours = 0.1667
mph=0.5/0.1667*/
mspeed = (TotalDistance *3600)/60;
//mspeed =(steps*steplength)/63360*60;
NSString *speed = [NSString stringWithFormat:@"%2.2f",mspeed];
[mSpeed setText:speed];
//this for calculation of miles
TotalDistance = (steps *steplength)/1500;
NSString *distance =[NSString stringWithFormat:@"%5.3f",TotalDistance];
[miles setText:distance];
if (steps%20==0)
{
//And this for calorie calculation
cal++;
NSString *cal1 = [NSString stringWithFormat:@"%d",cal];
[calorie setText:cal1];
}else{
[timer1 invalidate];
}
}