mirror of https://github.com/espruino/BangleApps
47 lines
823 B
JavaScript
47 lines
823 B
JavaScript
|
// made using https://www.espruino.com/Making+Music
|
||
|
// Manic Monday tone by The Bangles
|
||
|
|
||
|
var SPEAKER_PIN = D18;
|
||
|
|
||
|
function freq(f) {
|
||
|
if (f===0) digitalWrite(SPEAKER_PIN, 0);
|
||
|
else analogWrite(SPEAKER_PIN, 0.5, {freq: f});
|
||
|
}
|
||
|
freq(1000);
|
||
|
freq(1500);
|
||
|
freq(0);
|
||
|
|
||
|
var pitches = {
|
||
|
'G': 207.65,
|
||
|
'a': 220.00,
|
||
|
'b': 246.94,
|
||
|
'c': 261.63,
|
||
|
'd': 293.66,
|
||
|
'e': 329.63,
|
||
|
'f': 369.99,
|
||
|
'g': 392.00,
|
||
|
'A': 440.00,
|
||
|
'B': 493.88,
|
||
|
'C': 523.25,
|
||
|
'D': 587.33,
|
||
|
'E': 659.26,
|
||
|
'F': 698.46
|
||
|
};
|
||
|
|
||
|
function step() {
|
||
|
var ch = tune[pos];
|
||
|
if (ch !== undefined) pos++;
|
||
|
if (ch in pitches) freq(pitches[ch]);
|
||
|
else freq(0); // off
|
||
|
}
|
||
|
|
||
|
var tune = "aggffefed";
|
||
|
var pos = 0;
|
||
|
|
||
|
setWatch(() => {
|
||
|
var playing = setInterval(step, 500);
|
||
|
if(playing === 0) clearInterval(playing);
|
||
|
}, BTN1);
|
||
|
|
||
|
E.showMessage('BTN1 to start', 'Manic Monday');
|