Jilt is a free and open source, simple, easy to use library that can read the motion sensor on Apple Powerbooks and MacBooks.
Apple added a wonderful feature to its laptops - an internal sensor that can measure the tilt and gravity.
They do this in order to protect the data on the hard disk; in case you drop your laptop, the operating system can quickly shut down the hard disk before the computer crashes on the floor.
Of course, such a sensor can do a lot more, and it would be a pity to use it only for computers that crash on the floor.