• @Mrbpp,

    I assume

    • it is just 1bpp color depth... as in the lcd
    • the display has 8 rows and 8 cosl (16 cols) ?

    If you declare your text buffer to be 64,8,1 and vertical byte and write your text in to it, you just grab 8 bytes from any position and copy it to the display. You can use shift out.

    Was looking at the TM1640 data sheet. It requires to send upfront and at the end some commands:

    For filling the first 16 cols from the first 16 columns of our graphics buffer, you have to send (shift out) 0x40C0 for starters - data with address auto + 1 (0x40) and address (0xC0) - then 8 (16) bytes from text buffer for data (starting with any index, and finally the display control command - on and duty cycle - (I have no TM1640 device at hand - hope it works... no need to send one... (smileyFace) ).

    // scrollTextTM1640.js
    require("Font4x6").add(Graphics);
    var dev = true // devlopement  / runtime
      , dspDataPin  = B15 // B5 //
      , dspClockPin = B13 // B3 //
      , text        = "   Hi, this is me.   " // leading+trailing spaces intendedy
      , bufColsMax  =  960 // (pixel) max cols 'compose' buf of graphic object g has
      , frameTime   =  100 // [ms] - frame time
      , dspCols     =   16 // (pixel) cols the display shows
      , x           =   -1 // index 'compose' buffer
      , bufColsUsed // (pixel) cols the 'compose' buffer of graphic object g are used
      , bufColStrtX // buffer col start maximum (acutally ...+1)
      , g           // graphics object
      , iId         // 'scroll' intervall id
      , dspBuf      // view port on graphics buffer to output / shift out to display
      , dsp = function() {
          if (++x>=bufColStrtX) x = 0;
          dspBuf = new Uint8Array(g.buffer, x, dspCols);
          // data w/ auto + addr, addr, data bytes, on w/ 11/16 duty (brightness)
          shiftOut(dspDataPin, { clk: dspClockPin, repeat: 8 }, [0x40,0xC0]);
          shiftOut(dspDataPin, { clk: dspClockPin, repeat: 8 }
                             , { data: dspBuf, count: 8} );
          shiftOut(dspDataPin, { clk: dspClockPin, repeat: 8 }, [0x8C]);
        }
      , setup = function() {
          pinMode(dspDataPin ,"output");
          pinMode(dspClockPin,"output"); dspClockPin.set();
          if (iId) iId = clearInterval(iId);
          g = Graphics.createArrayBuffer( bufColsMax, 8, 1
                      ,{ vertical_byte: true } ); // one long text row
          g.clear();
          g.setFont4x6();
          g.drawString(text,0,0);
          bufColsUsed = g.stringWidth(text);
          bufColStrtX = ((bufColStrtX = bufColsUsed - dspCols) < 0) ? 0 : bufColStrtX;
          iId = setInterval(dsp, frameTime);
        }  
      , onInit = function() {
          setup();
        }
      ;
    if (dev) setTimeout(onInit,999);
    

    1 Attachment

About

Avatar for allObjects @allObjects started