A while ago I found out that the tilt sensor in my Macbook works as a joystick and I figured that I might as well have some fun with it…
First of all I installed a kernel module that will make the tilt sensor work, as well as a perl module using CPAN:
sudo modprobe applesmc; sudo cpan -i Linux::Joystick

Then, use this script to see the tilt sensor in action:

use Linux::Joystick;
my $js = new Linux::Joystick;
my $event;
print “Joystick has ” . $js->buttonCount() . ” buttons and ” . $js->axisCount() . ” axes.”;
# blocking reads:
while( $event = $js->nextEvent ) {
print “Event type: ” . $event->type . “, “;
if($event->isButton) {
print “Button ” . $event->button;
if($event->buttonDown) {
print ” pressed”;
} else {
print ” released”;
}
} elsif($event->isAxis) {
print “Axis ” . $event->axis . “, value ” . $event->axisValue . “, “;
print “UP” if $event->stickUp;
print “DOWN” if $event->stickDown;
print “LEFT” if $event->stickLeft;
print “RIGHT” if $event->stickRight;
} else {
# should never happen
print “Unknown event ” . $event->hexDump;
}
print “”;
}
# if the while loop terminates, we got a false (undefined) event:
die “Error reading joystick: ” . $js->errorString;

Now I just have to figure out what to do with this newly gained information. By the way, you can play neverball using the tilt sensor.

Related posts:

Tags: , ,

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage.