-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwa-buzzer.html
92 lines (83 loc) · 2.06 KB
/
wa-buzzer.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
<html>
<head>
<script type="text/javascript" src="../webduino-js/src/module/Buzzer.js"></script>
</head>
<body>
<script>
(function() {
var proto = Object.create(HTMLElement.prototype, {
pin: {
get: function() {
return this.getAttribute('pin');
},
set: function(val) {
this.setAttribute('pin', val);
}
},
notes: {
get: function() {
return this.getAttribute('notes');
},
set: function(val) {
this.setAttribute('notes', val);
}
},
tempos: {
get: function() {
return this.getAttribute('tempos');
},
set: function(val) {
this.setAttribute('tempos', val);
}
},
frequency: {
get: function() {
return this.getAttribute('frequency');
},
set: function(val) {
this.setAttribute('frequency', val);
}
},
duration: {
get: function() {
return this.getAttribute('duration');
},
set: function(val) {
this.setAttribute('duration', val);
}
},
autoplay: {
get: function() {
return this.getAttribute('autoplay');
},
set: function(val) {
this.setAttribute('autoplay', val);
}
}
});
proto.init_ = function(board) {
var Buzzer = webduino.module.Buzzer;
this.buzzer = new Buzzer(board, board.getDigitalPin(this.pin));
if (this.autoplay !== null) {
this.play();
}
};
proto.play = function() {
if (this.notes) {
this.buzzer.play(this.notes.split(','), this.tempos.split(','));
} else if (this.frequency) {
this.buzzer.tone(parseInt(this.frequency), parseInt(this.duration));
}
};
proto.attributeChangedCallback = function(attrName, oldVal, newVal) {
if (this.buzzer && this.autoplay !== null) {
this.play();
}
};
document.registerElement('wa-buzzer', {
prototype: proto
});
})();
</script>
</body>
</html>