-
Notifications
You must be signed in to change notification settings - Fork 14
/
wa-photocell.html
51 lines (42 loc) · 1018 Bytes
/
wa-photocell.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
<html>
<head>
<script type="text/javascript" src="../webduino-js/src/module/Photocell.js"></script>
</head>
<body>
<script>
(function() {
var proto = Object.create(HTMLElement.prototype, {
analogpin: {
get: function() {
return this.getAttribute('analogpin');
},
set: function(val) {
this.setAttribute('analogpin', val);
}
}
});
proto.init_ = function(board) {
var Photocell = webduino.module.Photocell;
this.photocell = new Photocell(board, this.analogpin);
};
proto.on = function(callback) {
if (typeof callback === 'function') {
this.photocell.on(function(val) {
val = val.toFixed(5);
callback(val);
});
}
};
proto.off = function() {
this.photocell.off();
};
proto.detachedCallback = function() {
this.off();
};
document.registerElement('wa-photocell', {
prototype: proto
});
})();
</script>
</body>
</html>