forked from mcqn/PerceptiveMedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
105 lines (104 loc) · 2.65 KB
/
test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<html>
<head><title>Testing analogRead</title>
<script src="client.js" charset="utf-8" type="text/javascript"></script>
<script type="text/javascript">
var ultrasonic = 0;
var light = 0;
var mic = 0;
var micSize = 20;
var micVals = [0,0,0,0,0,0,0,0,0,0];
var micIdx = 0;
var line = 0;
var smoothIdx = function(val)
{
var ret = 0;
micSize = $('#micSize')[0].value;
micIdx++;
if (micIdx == micSize) micIdx = 0;
micVals[micIdx] = val;
//console.log("Smoothing...");
for (i =0; i < micSize; i++)
{
ret = ret + micVals[i];
//console.log(ret);
}
$('#ret').text(ret);
return ret/micSize;
}
var smooth = function(smoothedVal, val)
{
var smoothingFactor = $('#factor')[0].value;
return (smoothedVal*smoothingFactor)+(val*(1-smoothingFactor));
}
arUpdateSlider_39 = function(x) {
if (x.value) {
$("#P9_39").text(x.value);
ultrasonic = smooth(ultrasonic, x.value);
$("#ultrasonic").text(ultrasonic);
}
};
arUpdateSlider_33 = function(x) {
if (x.value) {
$("#P9_33").text(x.value);
//mic = smooth(mic, x.value);
mic = smoothIdx(x.value);
$("#mic").text(mic);
}
};
arUpdateSlider_35 = function(x) {
if (x.value) {
$("#P9_35").text(x.value);
light = smooth(light, x.value);
$("#light").text(light);
}
};
arUpdateSlider_37 = function(x) {
if (x.value) {
$("#P9_37").text(x.value);
line = smooth(line, x.value);
$("#line").text(line);
}
};
var interval39 = setInterval(function() {
analogRead(bone.P9_39, arUpdateSlider_39);
}, 100);
var interval33 = setInterval(function() {
smoothedRead(bone.P9_33, arUpdateSlider_33);
}, 100);
var interval35 = setInterval(function() {
analogRead(bone.P9_35, arUpdateSlider_35);
}, 100);
var interval37 = setInterval(function() {
analogRead(bone.P9_37, arUpdateSlider_37);
}, 100);
</script>
</head>
<body>
<h1>Testing analogRead</h1>
<p>Smoothing factor: <input type="text" name="factor" id="factor" value="0.5"></p>
<p>Mic sample count: <input type="text" name="micSize" id="micSize" value="15"></p>
<p>Ret: <span id="ret">0</span></p>
<table>
<tr>
<td>P9_39, ultrasonic:</td>
<td width="200px"><span id="ultrasonic">0</span></td>
<td><span id="P9_39">here</span></td>
</tr>
<tr>
<td>P9_33, mic</td>
<td><span id="mic">0</span></td>
<td><span id="P9_33">here</span></td>
</tr>
<tr>
<td>P9_35, light</td>
<td><span id="light">0</span></td>
<td><span id="P9_35">here</span></td>
</tr>
<tr>
<td>P9_37, line-out</td>
<td><span id="line">0</span></td>
<td><span id="P9_37">here</span></td>
</tr>
</table>
</body>
</html>