You are reading a single comment by @rmd6502 and its replies. Click here to read the full conversation.
  • 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);
    }
    

    1 Attachment

About

Avatar for rmd6502 @rmd6502 started