• ...DONE in JS: Buffer is controlled by Espruino built-in Graphics 'class'!!!

    The r() - in code looks weird... has lots of code! Looks almost as weird as the Graphics created ArrayBuffer (). For now r() is very 3x5x3 specific... generalization required...

    That's how the Graphics ArrayBuffer looks:

      This is how the Graphics created ArrayBuffer looks. 
      To support driving the LED matrix, two Uint16 views
      are created to do the shifting for odd rows and for
      prefixing the rows with a dummy nibble to meet the\
      SPI requirements of transmitting always 8 bits...
      upper-case BGR means bit is on (1), lower-case off (0).
        [-Byt0-][-Byt1-][-Byt2-][-Byt3-][-Byt4-]­[-Byt5-][-Byt6-][-Byt7-]
     R0 xbgrxbgR|   xbgr|      ||      ||      ||      ||      ||      |
        | 1   0||     2||      ||      ||      ||      ||      ||      |
        | 0   1|| 2    ||      ||      ||      ||      ||      ||      |
     R1 |      |xbgr   |xbgrxbgR|      ||      ||      ||      ||      |
        |      || 0    ||  2  1||      ||      ||      ||      ||      |
        |      ||     0||  1  2||      ||      ||      ||      ||      |
     R2 |      ||      ||      |xbgrxbgr|   xbgr|      ||      ||      |
        |      ||      ||      ||  1  0||     2||      ||      ||      |
        |      ||      ||      ||  0  1|| 2    ||      ||      ||      |
     R3 |      ||      ||      ||      |xbgr   |xbgrxbgr|      ||      |
        |      ||      ||      ||      || 0    || 2   1||      ||      |
        |      ||      ||      ||      ||     0|| 1   2||      ||      |
     R4 |      ||      ||      ||      ||      ||      |xbgrxbgr|   xbgR
        |      ||      ||      ||      ||      ||      ||  1  0||     2|
        |      ||      ||      ||      ||      ||      ||  0  1|| 2    |
        |  LSB || MSB  ||      ||      ||      ||      ||      |xxxx   |
        [=R0==even[0]==][--------------][=R3==ev­en[2]==][=R4==even[3]==]
                [-R1==odd[0]===][=R2===odd[1]==][-------­-------]
                  LSB     MSB 
      ('second number'lines - 10, 13, 16... are with option msb:true)
    

    Here the running code. It was cool to just talk to the cnvs (canvas) Graphics instance (directly in the console while display is running) with cnvs.setPixel(2,1,1); ....clear(...), ....drawLine(...), etc and see it reflected right away in the display...

    // ledMatrix6.js - adjusted to nibble bound pixel info
    //                 ...controlled with Graphics...!!!
    
    // code exploring led matrix display w/ Espruino board
    // Espruino-WiFi / Pico / Original / Puck
    
    // A canvas (display buffer) created by and understood
    // by Espruino Graphics 'class'. 3x5x(1R+1G_1B color)
    // consumes 8 bytes due to nibble bound pixels.
    var cnvs = Graphics.createArrayBuffer(3,5,4);
    // Set LEDs @ [0,0], [1,1], [2,4] Red on (top left LED,
    // 2nd col of 2nd row and last/3rd col in last/5th row:
    cnvs.setPixel(0,0,1);
    cnvs.setPixel(1,1,1);
    cnvs.setPixel(2,2,1);
    cnvs.setPixel(1,3,1);
    cnvs.setPixel(2,4,1);
    
    // Buffer Views on Graphics ArrayBuffer for scanning
    // (nibble manipulation):
    var dbfe = new Uint16Array(cnvs.buffer,0,4); // even bytes starting
    var dbfo = new Uint16Array(cnvs.buffer,1,3); // odd bytes starting
    
    var // connect definitions (Espruino -> 595 wiring): 
    //        SPI1 and other GPIOs          74HC595 (pin) 
      dspiDat=B5 // a) SDA ser data MOSI -> SER    (14)
    , dspiClk=B3 // b) SCK ser clock     -> SRCLK  (11)
    , dnss   =A0 // c) NSS to go w/ SPI  -> RCLK   (12)
    , dnoe   =A1 // d) 595 output enable -> _OE    (13)
    ;            // e) 595 _clear fix 1  -> _SRCLR (10)
    // A0 dnss is co-used for output register latch.
    //    Latch prevents blur while shifting.
    // A1 can do PWM when danger of over powering LEDs. 
    
    pinMode(dspiDat, "output"); dspiDat.set(); 
    pinMode(dspiClk, "output"); dspiClk.set();
    pinMode(dnss   , "output"); dnss.set();
    pinMode(dnoe   , "output"); dnoe.set();
    SPI1.setup({ mosi: dspiDat, sck: dspiClk });
    
    
    var iId       // interval ID and interval time w/
      , iTm = 10; // full scan event every 10 millisec
    
    function r() { // run / row drain bit (rBt) calculated
      iId = setInterval(function() {
          var rdxd=5, rdx=0, bdx=0, bex=0, box=0, rBt=0xFE, bs;
          dnoe.reset(); // enable output
          while (rdxd--) {
            bs = rdx % 4;
            if        (bs === 0) {
              v = dbfe[bex] & 0x0FFF;
              SPI1.write([v>>8, v & 0xFF, rBt],dnss);
              bex++;
            } else if (bs === 1) {
              v = dbfo[box] >> 4;
              SPI1.write([v>>8, v & 0xFF, rBt],dnss);
              box++;
            } else if (bs === 2) {
              v = dbfo[box] & 0x0FFF;
              SPI1.write([v>>8, v & 0xFF, rBt],dnss);
              box++;
              bex++;
            } else if (bs === 3) {
              v = dbfe[bex] >> 4;
              SPI1.write([v>>8, v & 0xFF, rBt],dnss);
              bex++;
            }
            rdx++;
            rBt = (rBt<<1) | 0x01;
          }
          dnoe.set();   // disable output
        }, iTm);
    }
    
    function h() { // halt
      if (iId) iId = clearInterval(iId);
      dnoe.set();
    }
    
    setTimeout(r,100);
    
About

Avatar for allObjects @allObjects started