| 1 |
Hid hi; |
| 2 |
HidMsg msg; |
| 3 |
|
| 4 |
if( !hi.openTiltSensor() ) |
| 5 |
{ |
| 6 |
<<< "tilt sensor unavailable", "" >>>; |
| 7 |
me.exit(); |
| 8 |
} |
| 9 |
|
| 10 |
<<< "tilt sensor ready", "" >>>; |
| 11 |
|
| 12 |
while( true ) |
| 13 |
{ |
| 14 |
hi.read( Hid.ACCELEROMETER, 0, msg ); |
| 15 |
|
| 16 |
// x: positive to left of user, negative to right of user |
| 17 |
// y: positive towards user, negative away from user |
| 18 |
// z: positive up, negative down |
| 19 |
<<< "acc x:", msg.x, "acc y:", msg.y, "acc z:", msg.z >>>; |
| 20 |
|
| 21 |
// theta: positive in counter-clockwise rotation in x-z plane |
| 22 |
// phi: positive rotation clockwise towards user y-z plane |
| 23 |
|
| 24 |
<<< "theta:", Math.atan2( msg.y, msg.z ) / pi, |
| 25 |
"phi:", Math.atan2( Math.sqrt( msg.z * msg.z + msg.y * msg.y ), -msg.x ) / pi >>>; |
| 26 |
|
| 27 |
.25::second => now; |
| 28 |
} |