Skip to content

Instantly share code, notes, and snippets.

@tkojitu
Last active August 29, 2015 14:01
Show Gist options
  • Save tkojitu/2369ad5b427ca2ef3bbe to your computer and use it in GitHub Desktop.
Save tkojitu/2369ad5b427ca2ef3bbe to your computer and use it in GitHub Desktop.
<html>
<head>
<script src="devmot.js"></script>
</head>
<body>
<table border=1>
<tr><td>x</td><td id="x">0</td></tr>
<tr><td>y</td><td id="y">0</td></tr>
<tr><td>z</td><td id="z">0</td></tr>
<tr><td>v</td><td id="v">0</td></tr>
</table>
</body>
</html>
function onLoad() {
window.addEventListener("devicemotion", onDeviceMotion, false);
}
function onDeviceMotion(event) {
var acc = event.accelerationIncludingGravity;
var x = acc.x;
var y = acc.y;
var z = acc.z;
var v = Math.sqrt(x * x + y * y + z * z);
showValue("x", x);
showValue("y", y);
showValue("z", z);
showValue("v", v);
}
function showValue(id, value) {
var elm = document.getElementById(id);
elm.innerHTML = "" + value;
}
window.addEventListener("load", onLoad, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment