You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • digitalWrite executes right to left (least-significant bit first)

    You're right about the /127, but it's not quite 127, it's 127.000060558 - and I believe that makes a difference. You could try it and see I guess...

    There was a discussion elsewhere on here, but if you break the multiply down, you get:

    x*0b100000010000001 =
      x*0b100000000000000 +
      x*0b000000010000000 +
      x*0b000000000000001 =
      x << 14 +
      x << 7 +
      x
    

    If you assume that the 3 bits you want are as follows:

    x = R0000000G0000000B0000000
    

    Then when you do that multiply you get:

    R0000000G0000000B000000000000000000000 +
    0000000R0000000G0000000B00000000000000 +
    00000000000000R0000000G0000000B0000000
    
    = R000000RG00000RGB00000GB000000B0000000
    

    And then when you shift it down and & with 7 you get:

    = R000000RG00000RGB & 7
    = RGB
    

    Anyway, it's a bit of a nasty hack. Precalculating so as to avoid having to do that would be much better :)

About

Avatar for Gordon @Gordon started