### Author Topic: Shake my iphone?  (Read 2385 times)

#### ampos

• Prof. Inline
• Posts: 1594
##### Shake my iphone?
« on: 2011-Jan-14 »
Does someone has a function to detect if the iPhone has been shaked?

Thank you.
check my web and/or my blog
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

#### matchy

• Prof. Inline
• Posts: 1544
##### Re: Shake my iphone?
« Reply #1 on: 2011-Jan-14 »
That's something I have wondered about lately also (for a magic eight ball style app).

When shaken (not "shaked" or stirred) I'd imagine just toggling the extremes although haven't tried any yet. Wouldn't it be just a case of measuring the sensor change amounts? What a x,y,z graph look like?

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10725
• here on my island the sea says 'hello'
##### Re: Shake my iphone?
« Reply #2 on: 2011-Jan-14 »
I'd test for X > 1.5

#### phaelax

• Mc. Print
• Posts: 36
##### Re: Shake my iphone?
« Reply #3 on: 2011-Jan-29 »

#### matchy

• Prof. Inline
• Posts: 1544
##### Re: Shake my iphone?
« Reply #4 on: 2011-Jan-29 »
Something like this works for me:
Code: (glbasic) [Select]
`// shakey shakeyFUNCTION shake_input: IF oMouse[0].xjoy<-0.25 AND shake_toggle<>-1 shake_toggle=-1 ENDIF IF oMouse[0].xjoy>0.25 AND shake_toggle<>1 OR KEY(KEY_SPACE) shake_toggle=1 INC shake_count,2 IF shake_count>10 shake_count=0 // shaken ENDIF ENDIF IF shake_count>0 LOCAL temp_sin=SIN(GETTIMERALL()) IF temp_sin>0.99 DEC shake_count ENDIF ENDIFENDFUNCTION`
Also:
ALPHAMODE shake_count/10.0 /// in loop for fade-out