문제

Id have an app that does one thing if you shake it one way, and another if you shake it the other.

atm my code is.

if (acceleration.x > 1.5) {

//arm to the right when facing you

    float duration = ([imageArray count]*0.04);

    //HUMAN EYE KEEPS IMAGES IN EYE For 40 MILLISECONDS//
    //NSLog(@"duration:%f", duration);
    [theFlash setAnimationImages:imageArray];
    [theFlash setAnimationRepeatCount:1];
    theFlash.animationDuration = duration;
    [theFlash startAnimating];
    NSLog(@"images flashed forward");   

}

if (acceleration.x < -1)
{
    //arm to the left when facing you

    float duration = ([imageArrayReversed count]*0.04);

    //HUMAN EYE KEEPS IMAGES IN EYE For 40 MILLISECONDS//
    NSLog(@"duration:%f", duration);
    [theFlash setAnimationImages:imageArrayReversed];
    [theFlash setAnimationRepeatCount:1];
    theFlash.animationDuration = duration;
    [theFlash startAnimating];
    NSLog(@"images flashed backward");  

}

the 1 and -1 values are working on it not being too sensitive.

however, this code is not giving me the results desired. Id like the images to flash (see the code) as soon as the person starts moving the device the other way.

Any way to do this?

도움이 되었습니까?

해결책

Well, you're going to have to integrate the acceleration to get velocity. Unfortunately, the accelerometer is a bit noisy and will inevitably drift a bit, so you're going to have to filter that integral. I think the filter described at http://www.musicdsp.org/showone.php?id=92 will do what you need, with the cutoff frequency set to around 1/4 the sampling frequency. You need the band output, and you'll have to tune the resonance parameter.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top