BangleApps/apps/jbells/jbells.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-11-12 10:16:09 +00:00
E.showMessage("Jingle Bells");
var eventEmitter = new Object();
function strofa(notes, times, current, next){
eventEmitter.on(current, () => {
2019-11-12 10:16:09 +00:00
if (notes.length == 0) {
eventEmitter.emit(next);
return;
2019-11-12 10:16:09 +00:00
}
let note = notes.shift();
let time = times.shift();
Bangle.beep(time, note).then(() => {
setTimeout(() => {
2019-11-12 10:16:09 +00:00
eventEmitter.emit(current);
}, time);
2019-11-12 10:16:09 +00:00
});
});
2019-11-12 10:16:09 +00:00
}
var one = [2637, 2637, 2637, 2637, 2637, 2637, 2637, 3135, 2093, 2349, 2637];
var one_t = [160, 160, 320, 160, 160, 320, 160, 160, 160, 160, 320];
var two = [2793, 2793, 2793, 2637, 2637, 2637, 2349, 2349, 2349, 2637, 2349, 3135];
var two_t = [160, 160, 320, 160, 160, 320, 160, 160, 160, 160, 320, 320];
var three = [2637, 2637, 2637, 2637, 2637, 2637, 2637, 3135, 2093, 2349, 2637];
var three_t = [160, 160, 320, 160, 160, 320, 160, 160, 160, 160, 320];
var four = [2793, 2793, 2793, 2637, 2637, 2637, 3135, 2793, 2637, 2349, 2093];
var four_t = [160, 160, 320, 160, 160, 320, 160, 160, 160, 160, 320];
strofa(one, one_t, "one", "two");
strofa(two, two_t, "two", "three");
strofa(three, three_t, "three", "four");
strofa(four, four_t, "four", "stop");
eventEmitter.emit("one");