Thanks to @GordonGordon's and @allObjects' suggestions I've distilled the code to the following, as well as wiring up the rest of the cathodes and anodes, resulting in the attached video.
const cathodes = [D24,D28,D27,D23];
const anodes = [D31,D1,D11,D29,D2,D30,D6,D7];
const patterns = [63,6,91,79,102,109,125,7,127,111];
const zero = '0'.charCodeAt(0);
var count = 0;
var k = 3;
var pattern = " 0";
function onInit() {
setTimeout(update, 0);
setInterval(() => {
if (++count == 10000) {
count = 0;
}
pattern = (" " + count.toString()).slice(-4);
}, 25);
}
function update() {
"compiled";
digitalWrite(anodes, 0);
digitalWrite(cathodes[k++], 1);
if (k >= cathodes.length) {
k = 0;
}
var ch = pattern[k];
if (ch >= '0' && ch <= '9') {
digitalWrite(cathodes[k], 0);
digitalWrite(anodes, patterns[ch.charCodeAt(0) - zero]);
}
setTimeout(update, 0);
}
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.
Thanks to @GordonGordon's and @allObjects' suggestions I've distilled the code to the following, as well as wiring up the rest of the cathodes and anodes, resulting in the attached video.
1 Attachment