Air 2.0 Accelerometer component for MacBooks

21 12 2009

Ever wanted to build super cool Games/Applications/Demos on your MacBook using Accelerometer ?

Yes, it is now possible to build all these cool stuff with Air 2.0 & MacBook.

MacBooks have a device called SMS ( Sudden Motion Sensor ) which can act as our Accelerometer. And using Air 2.0′s NativeProcess, we can invoke a native program to give us the Accelerometer data. Here is how the flow goes:

Accelerometer Flow Chart

I got a simple C-Program called “motion” (bundled in the below package) which can give me X,Y & Z co-ordinates of Accelerometer & print on the console. I execute the process using NativeProcess API & capture the console output.

I made a wrapper class called “MBAcceleromoter” to make this entire process easier.

Click here to download the source & demo. ( Air 2.0 SDK required )

Click here to download Demo alone. ( Air 2.0 runtime required )

This package contains:

1. “motion” program to capture Accelerometer data

2. “MBAccelerometer” class to invoke & “motion” program & returned structured output through event dispatch mechanism.

3. Sample application (Accelerometer.mxml) built using APE

What are you waiting for ? Go ahead & create some amazing stuff.

Here is what I have built in this demo:

Demo – Base position

Demo – Tilted Left

Demo – Tilted Right

About these ads

Actions

Information

2 responses

12 03 2010
B

Shouldn’t you be able to do something like this?

import flash.sensors.Accelerometer;

var acc = new Accelerometer();
acc.addEventListener(‘update’, trace);

Any idea what the minimum requirements are for native Accelerometer support? It doesn’t seem to work on my Vista tablet.

13 03 2010
Srinivas Annam

You are right. That is the case for devices which have accelerometer support. But, Macbook does not have Accelerometer in it. That is why this post uses a round about way of using “Sudden Motion Sensors (SMS)” as Accelerometer. If the device actually had a Accelerometer, you could directly use the new inbuilt Accelerometer APIs provided by Air 2.0.

Device with Accelerometer & Air 2.0 are the only two requirements for using inbuilt Accelerometer APIs. But, you need to have a MacBook & Mac OS running Air 2.0 for the current SMS based example to work.

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




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: