-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathsound.js
More file actions
18 lines (15 loc) · 1.7 KB
/
sound.js
File metadata and controls
18 lines (15 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var notes = {"C0":"16","C#0":"17","D0":"18","D#0":"19","E0":"20","F0":"21","F#0":"23","G0":"24","G#0":"25","A0":"27","A#0":"29","B0":"30","C1":"32","C#1":"34","D1":"36","D#1":"38","E1":"41","F1":"43","F#1":"46","G1":"49","G#1":"51","A1":"55","A#1":"58","B1":"61","C2":"65","C#2":"69","D2":"73","D#2":"77","E2":"82","F2":"87","F#2":"92","G2":"98","G#2":"103","A2":"110","A#2":"116","B2":"123","C3":"130","C#3":"138","D3":"146","D#3":"155","E3":"164","F3":"174","F#3":"185","G3":"196","G#3":"207","A3":"220","A#3":"233","B3":"246","C4":"261","C#4":"277","D4":"293","D#4":"311","E4":"329","F4":"349","F#4":"369","G4":"392","G#4":"415","A4":"440","A#4":"466","B4":"493","C5":"523","C#5":"554","D5":"587","D#5":"622","E5":"659","F5":"698","F#5":"739","G5":"783","G#5":"830","A5":"880","A#5":"932","B5":"987","C6":"1046","C#6":"1108","D6":"1174","D#6":"1244","E6":"1318","F6":"1396","F#6":"1479","G6":"1567","G#6":"1661","A6":"1760","A#6":"1864","B6":"1975","C7":"2093","C#7":"2217","D7":"2349","D#7":"2489","E7":"2637","F7":"2793","F#7":"2959","G7":"3135","G#7":"3322","A7":"3520","A#7":"3729","B7":"3951","C8":"4186","C#8":"4434","D8":"4698","D#8":"4978"};
var Sound = function (options) {
if (!options || !options.board) throw new Error('Must supply required options to LED');
this.board = options.board;
this.pin = options.pin || 8;
this.board.pinMode(this.pin, 'out');
}
Sound.prototype.tone = function(tone,duration) {
this.board.write('95' + this.board.lpad(2, '0', this.pin) + this.board.lpad(6,'0',tone));
this.board.write('96' + this.board.lpad(2, '0', this.pin) + this.board.lpad(6,'0',duration));
}
Sound.prototype.note = function(note, duration) {
this.tone(notes[note],duration);
}
module.exports = Sound;