Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
if (shakeme) return; beenhere = TRUE; if (acceleration.x > earthquake || acceleration.x < (-1* earthquake)) shake = TRUE; if (acceleration.y > earthquake || acceleration.y < (-1* earthquake)) shake = TRUE; if (acceleration.z > earthquake || acceleration.z < (-1* earthquake)) shake = TRUE; if (shake) { /* perform action here */ }
shakeme = false; }
so if the action that you wanted to perform was to pull a random object/data from a sqlite3 database, it would be some rand code that randomized the Primary key, and whatever that value is ...send that data to the view or a label or imagecontroller
That does not detect a shake, only a large singe movement. My code detects several large movements, first one way, then another and also the frequency of the movement. Shake too slow, and its NOT a shake. Shake only once and its NOT a shake.
ive looked around quite a bit, and can't seem to find any examples of code to perform an action if the iphone is shaken
There is some sample code from the Beginning iPhone Development book that covers this. As I recall, it's Chapter 15 "ShakeandBreak" example. You can download the code even if you don't have the book, but I recommend the book if you're new to iPhone Dev.
Index Card | Comic Viewer | <a href="http://click.linksynergy.com/fs-bin/stat?id=e*p82eCraXo&offerid
Personally I have tried out the - (void)motionEnded...method and found the response time to be rather slow.
What I am trying to do is detect a fast shake vs. a slow shake and write a message. The project compiles, and if you shake below the 1.5 acceleration threshold I setup the labels says "Slow" as it is suppose to. Speed up the shake and it shows "Fast." THE PROBLEM is if I slow the shake back down the label doesn't change. What I have is as follows:
Replies
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration;
{
++frameNum;
if (acceleration.x > shakeLimit && shakeLeft == NO)
{
lastFrameFullRight = frameNum;
shakeLeft = YES;
if (lastFrameFullRight - lastFrameFullLeft < 15) // a shake
{
if (++numChanges > 3)
{
[self erase];
numChanges = 0;
}
}
else
numChanges = 0;
}
if (acceleration.x < -shakeLimit && shakeLeft == YES)
{
lastFrameFullLeft = frameNum;
shakeLeft = NO;
if (lastFrameFullLeft - lastFrameFullRight < 15) // a shake
{
if (++numChanges > 3)
{
[self erase];
numChanges = 0;
}
}
else
numChanges = 0;
}
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeEssentially calculating if the distance from the last point was above a certain threshold. The distance is calculated by:
#define DIST(X, Y, Z) sqrtf(((X)*(X))+((Y)*(Y))+((Z)*(Z)));
And used in:
dist = DIST(x - old_x, y - old_y, z - old_z);
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeMy code detects several large movements, first one way, then another and also the frequency of the movement.
Shake too slow, and its NOT a shake. Shake only once and its NOT a shake.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomewhat values you assigned for the variables at starting ...for
lastFrameFullRight , frameNum, shakeLimit.
Of course it is simple Question i am asking ....can you post it with total code.
thansk,
naren
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks in advance.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThis should do it :
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhat I am trying to do is detect a fast shake vs. a slow shake and write a message. The project compiles, and if you shake below the 1.5 acceleration threshold I setup the labels says "Slow" as it is suppose to. Speed up the shake and it shows "Fast." THE PROBLEM is if I slow the shake back down the label doesn't change. What I have is as follows:
- (void)accelerometer : (UIAccelerometer *)accelerometer
didAccelerate : (UIAcceleration *)acceleration {
static NSInteger shakeCount = 0;
static NSDate *shakeStart;
NSDate *now = [[NSDate alloc] init];
NSDate *checkDate = [[NSDate alloc] initWithTimeInterval: 2.0f sinceDate:shakeStart];
if ([now compare:checkDate]== NSOrderedDescending || shakeStart == nil) {
shakeCount = 0;
[shakeStart release];
shakeStart = [[NSDate alloc] init];
}
[now release];
[checkDate release];
// Shake is too fast
if (acceleration.y > AccelerationThreshold) {
shakeCount++;
if (shakeCount > 4) {
myLabel.text = [NSString stringWithFormat:@"To Fast %i", shakeCount];
NSLog(@"To Fast");
shakeCount = 0;
shakeStart == nil;
[shakeStart release];
shakeStart = [[NSDate alloc] init];
// shakeCheckComplete = YES;
}
}
// Shake is slow
if (acceleration.y < AccelerationThreshold && acceleration.y > 0.5) {
shakeCount++;
if (shakeCount > 5) {
myLabel.text = [NSString stringWithFormat:@"Slow %i", shakeCount];
NSLog(@"Slow");
shakeCount = 0;
shakeStart == nil;
[shakeStart release];
shakeStart = [[NSDate alloc] init];
}
}
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome