RSS

Accelerometer with Adobe Air

07 Jun
var accl:Accelerometer; 
var rollingX:Number = 0; 
var rollingY:Number = 0; 
var rollingZ:Number = 0; 
const FACTOR:Number = 0.25; 

if (Accelerometer.isSupported) 
{ 
    accl = new Accelerometer(); 
    accl.setRequestedUpdateInterval(200); 
    accl.addEventListener(AccelerometerEvent.UPDATE, updateHandler); 
} 
else 
{ 
    accTextField.text = "Accelerometer feature not supported"; 
} 
function updateHandler(event:AccelerometerEvent):void 
{ 
    accelRollingAvg(event); 
    accTextField.text = rollingX + "\n" +  rollingY + "\n" + rollingZ + "\n"; 
} 

function accelRollingAvg(event:AccelerometerEvent):void 
{ 
    rollingX = (event.accelerationX * FACTOR) + (rollingX * (1 - FACTOR)); 
    rollingY = (event.accelerationY * FACTOR) + (rollingY * (1 - FACTOR)); 
    rollingZ = (event.accelerationZ * FACTOR) + (rollingZ * (1 - FACTOR)); 
}
Read More
Advertisements
 
Leave a comment

Posted by on June 7, 2011 in Action Script3, Android, flash, iPhone

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: