Hi, I was just messing around, and realised I'd added the ability to play more than one Waveform at once on the same output a while back, but had never shown it in use.
So...
var pitches = {
'A':440.00, 'B':493.88, 'C':523.25, 'D':587.33,
'E':659.26, 'F':698.46, 'G':783.99, 'a':880
};
var tune = "E BCD CBA ACE DCB CD E C A A D Fa GFE CE DCB BCD E C A A ";
var s = atob("f4GBgoODh5GtnmgkE1m435g/MobgzYJbd41YHkHD/7UoEZPysyscl/K5PSqLy5tLToqdfHGdrXI1V7vUeiVIqceEUG2kmWVfj6qIWFuKpZFpXXiXknNthZB9cH6LgG5vgJKSdWF7oZVoXHuRioJ8c3iJjHtweomLf3JygpCHdHOCiYJ8fYCBg4ODgn53d4CGiIZ8cHGAjo1+dn6Jh3pzeoWHfXd8hYd8d3+Gg3t1e4F9d36KiHp0fYZ+cneLlol3cnyEgXt8g4WBeXV8hoqDdnOCjoNxc4aRhnd3f4J6cXmNlIJxd4mKeXJ5iI2Denh9fX1/f4B/g4N2bnuSlYJzdoOIgXp7g4V+dnmDhoF9gIF+eHqDioJyb3+Oi3xzeIOHgXp7gIB+fH+DgHt8hIh/cnOEjoVzb32Mi3pxeYeLf3N2hIqBdXaBhoB7fYSGfXZ7hYeAeXl9goJ9e36BgYGCgoF8e4GDgHp6f4ODgHo=");
var w = new Waveform(s.length);
var w2 = new Waveform(s.length);
var w3 = new Waveform(s.length);
w.buffer.set(s);
w2.buffer.set(s);
w3.buffer.set(s);
s=undefined;
function step() {
var ch = tune[pos];
if (ch !== undefined) pos++; else pos=0;
if (ch in pitches) {
if (!w.running)
w.startOutput(B0, 4000*pitches[ch]/2500);
else if (!w2.running)
w2.startOutput(B0, 4000*pitches[ch]/2500);
else if (!w3.running)
w3.startOutput(B0, 4000*pitches[ch]/2500);
}
}
var pos=0;
function onInit() {
pinMode(B0, "af_opendrain");
analogWrite(B0, 0.5, {freq:20000});
setInterval(step, 150);
}
Tetris music - not hi-fi quality, but it sounds pretty old-school :)
You might want to change pinMode(B0, "af_opendrain"); if you're not using a Pico (it was running on the FET output to get a bit of volume).
It'd be great if someone wanted to add another track so it actually was properly polyphonic. At the moment it's just playing overlapping waveforms (rather than actual different notes).
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi, I was just messing around, and realised I'd added the ability to play more than one Waveform at once on the same output a while back, but had never shown it in use.
So...
Tetris music - not hi-fi quality, but it sounds pretty old-school :)
You might want to change
pinMode(B0, "af_opendrain");
if you're not using a Pico (it was running on the FET output to get a bit of volume).It'd be great if someone wanted to add another track so it actually was properly polyphonic. At the moment it's just playing overlapping waveforms (rather than actual different notes).