pbrinkmeier.de/gyro/index.html

27 lines
731 B
HTML

<!DOCTYPE html>
<html>
<body>
<h1>Is it working?</h1>
<button id="perm">click me for permissions</button>
<div style="color: red" id="disp">lalala</div>
<script>
document.querySelector("#perm").addEventListener("click", e => {
const ac = new AudioContext();
const osc = ac.createOscillator();
osc.type = "square";
osc.frequency.setValueAtTime(440, ac.currentTime);
osc.connect(ac.destination);
osc.start();
DeviceMotionEvent.requestPermission().then(response => {
window.addEventListener("devicemotion", e => {
document.querySelector("#disp").innerHTML = Math.round(e.acceleration.x);
osc.frequency.setValueAtTime(440 * Math.pow(2, e.acceleration.x / 10), ac.currentTime);
});
});
});
</script>
</body>
</html>