问题描述:

I have to develop an application where it does following things,

  1. Switch is used to initiate the accelerometer
  2. Then accelerometer data is inserted to an array of size 5
  3. Then use those accelerometer data to calculate a output value using a equation
  4. Every times a new reading comes, i delete the last element of the array and add it to the array( array remains dynamic through out the loop
  5. Then i want to compare whether the output calculated is greater than a specified value and update a global counter?

I implemented this by using a if condition

if(output>10){

[[shared sharedInstance].counter++;

}

(all above are implemented and they work perfectly)

BUT the problem is.....................

I want to check this if condition, used to update to be active for 5ms and deactivate for 10ms but it's also important to "NOT" to stop the accelerometer data process and calculating output.

So i thought that i can implement two global variables and set their values as shown below

1. var_x - set it's value for 1 for 5ms after that set it to 10ms and this process should repeat continuously and it should start after the user activate accelerometer,

So by using this inside my if condition i can make sure it check the condition after 10ms and keep on checking for 5ms

like this.........

if(output>10 && [[shared sharedInstance].var_x >1){

[[shared sharedInstance].counter++;

}

can anyone help me to code this timing function inside the global variable to set the variable value to 1 and 0 ? (

网友答案:
- (void)turnCheckOn {
    doCheck = YES;
    [self performSelector:@selector(turnCheckOff) withObject:nil afterDelay:0.005];
}

- (void)turnCheckOff {
    doCheck = NO;
    [self performSelector:@selector(turnCheckOn) withObject:nil afterDelay:0.010];
}

Then call turnCheckOn once.

相关阅读:
Top