-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathSound.js
More file actions
48 lines (39 loc) · 965 Bytes
/
Sound.js
File metadata and controls
48 lines (39 loc) · 965 Bytes
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
+(function (global, factory) {
if (typeof exports === 'undefined') {
factory(global.webduino || {});
} else {
module.exports = factory;
}
}(this, function (scope) {
'use strict';
var PinEvent = scope.PinEvent,
Pin = scope.Pin,
Module = scope.Module;
var SoundEvent = {
DETECTED: 'detected',
ENDED: 'ended'
};
function Sound(board, pin) {
Module.call(this);
this._type = 'FC_04';
this._board = board;
this._pin = pin;
board.setDigitalPinMode(pin.number, Pin.DIN);
this._pin.value = Pin.HIGH;
this._pin.on(PinEvent.CHANGE, onPinChange.bind(this));
}
function onPinChange(pin) {
if (pin.value === Pin.LOW) {
this.emit(SoundEvent.DETECTED);
} else {
this.emit(SoundEvent.ENDED);
}
}
Sound.prototype = Object.create(Module.prototype, {
constructor: {
value: Sound
}
});
scope.module.SoundEvent = SoundEvent;
scope.module.Sound = Sound;
}));