-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmartOLED.html
66 lines (57 loc) · 1.71 KB
/
smartOLED.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
<html>
<head>
<script src="bower_components/webduino-js/dist/webduino-all.js"></script>
<script src="SSD1306.js"></script>
<style>
.btn {
font-size: 2em;
}
</style>
</head>
<body>
<input id='str' type='text' style='font-size:2em' value="Detect:">
</input>
<button id='btn' class='btn'>Send</button>
<script>
var board, photoCell, OLED, lastVal;
board = new webduino.Arduino({
'transport': 'websocket',
'url': location.hash.substring(1)
});
board.on(webduino.BoardEvent.READY, function() {
console.log("Ready...");
OLED = new SSD1306(board);
photocell = new webduino.module.Photocell(board, 0);
btn.addEventListener('click', function() {
photocell.on(function(val) {
var val = (Math.round(val * 100)) / 100;
if (lastVal == val) {
return;
}
OLED.clear();
OLED.textSize = 2;
OLED.print(0, 0, str.value);
lastVal = val;
OLED.textSize = 4;
OLED.print(30, 30, "" + val);
});
});
});
board.on(webduino.BoardEvent.ERROR, function(err) {
console.log('board error', err.message);
});
board.on(webduino.BoardEvent.BEFOREDISCONNECT, function() {
console.log('board beforedisconnect');
});
board.on(webduino.BoardEvent.DISCONNECT, function() {
console.log('board disconnect');
board.disconnect();
});
board.on(webduino.BoardEvent.STRING_MESSAGE,
function(event) {
var m = event.message;
console.log("STRING:", m);
});
</script>
</body>
</html>