-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
56 lines (50 loc) · 1.67 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="riffwav.js"></script>
<script type="text/javascript" src="servo.js"></script>
</head>
<body>
<script type="text/javascript">
var lastx = 0;
var lasty = 0;
var lastz = 0;
var lastEvent = 0;
window.ondevicemotion = function (event) {
var threshold = 10;
var ax = event.accelerationIncludingGravity.x
var ay = event.accelerationIncludingGravity.y
var az = event.accelerationIncludingGravity.z
if (lastx == 0) {
lastx = Math.abs(ax);
lasty = Math.abs(ay);
lastz = Math.abs(az);
}
if(lastEvent > 0){
lastEvent--;
}
if(lastEvent == 0 && (Math.abs(lastx - Math.abs(ax)) > threshold || Math.abs(lasty - Math.abs(ay)) > threshold || Math.abs(lastz - Math.abs(az)) > threshold)){
jQuery('#msgs').append("Too much change");
ServoJs.moveTo(1, 0);
setTimeout(function(){
ServoJs.moveTo(1, 100);
}, 400);
setTimeout(function(){
ServoJs.moveTo(1, 0);
}, 800);
lastEvent = 20;
}
lastx = Math.abs(ax);
lasty = Math.abs(ay);
lastz = Math.abs(az);
jQuery('#ax').html(Math.round(ax * 100) / 100.0);
jQuery('#ay').html(Math.round(ay * 100) / 100.0);
jQuery('#az').html(Math.round(az * 100) / 100.0);
}
</script>
X: <span id="ax">?</span>
Y: <span id="ay">?</span>
Z: <span id="az">?</span>
Z: <span id="msgs">?</span>
</html>