You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Right, so what I meant is that while your display accepts the data as you say, the Graphics library in 1v61 will interleave red and green (like it would for any other bit depth). I'm not going to do a fancy colour diagram, but the data will look like:

    RGRGRGRGRGRGRGRG
    RGRGRGRGRGRGRGRG
    RGRGRGRGRGRGRGRG
    RGRGRGRGRGRGRGRG
    RGRGRGRGRGRGRGRG
    RGRGRGRGRGRGRGRG
    RGRGRGRGRGRGRGRG
    RGRGRGRGRGRGRGRG
    

    So the code I had with the crazy shifting stuff will turn that into what you had (eventually).

    If you don't want to use graphics and just want to carry on as you are, and you want to do it quickly, I'd suggest just repeating the code you have 16 times (once for each nibble):

    i2c.writeTo(address, [0,
    ((rowValue & 0x0F) << 4) | ((rowValue & 0xF0) >> 4),
    ((rowValue & 0x0F00) >> 4) | ((rowValue & 0xF000) >> 12),
    ...
    ]);
    

    You might find that putting it into a Uint16Array and doing a view of it was easier, but to be honest you'd have to benchmark:

    var u16 = new Uint16Array([0,
    ((rowValue & 0x0F0F) << 4) | ((rowValue & 0xF0F0) >> 4),
    ...]);
    var u8 = new Uint8Array(u16.buffer, 1); // <-- 1 because the '0' above took up 2 bytes
    i2c.writeTo(address,u8);
    

    PS. Multiply-AND tricks are fun. If you think about what is going on with a multply, it's like a repeated shift-add:

    a * b = 
       (a&1) ? b<<0 : 0 + 
       (a&2) ? b<<1 : 0 + 
       (a&4) ? b<<2 : 0 + 
      ...
    

    So if you multiply by 5 (0b0101) you've got:

    5 * b =  b<<0 + b<<2;
    

    So it's potentially 64 shift and adds in a single operation :)

About

Avatar for Gordon @Gordon started