I am using Arduino Uno to power a Nokia 6100 LCD. In my program, i take RGB 8 bit input which can be converted to 24 bit Hex using any available online conversion tools, that conversion i can take care of. However, the LCD library i am using only allows 12 bit Hex. how can i get the LCD to accept 24 bit Hex values instead of 12 and get the right colour on the screen. Or is there a way to change from 24 bit Hex to 12 bit hex in this case?
Thanks,
Faiz
Perhaps the LCD only understands 4bit channels? In any case, it sounds like that’s the limit of the library 🙂
To convert to a 12-bit value (3 channels x 4 bits/channel) from a 24-bit value (3 channels x 8 bits/channel), just scale down each channel by a factor of 24 — that is, divide each 8-bit channel value [0-255] by 16 to obtain the approximate value in a 4-bit channel [0-15].
Now, consider this: “dividing by 16” and “shifting right by 4” (non sign-extending) is effectively the same for unsigned 2’s complement integers. That is, the bottom 4 bits are just “thrown out”.
Imagine this 24-bit value, in bits (padded in 32-bit integer):
And this is the target value (padded in 16-bit integer):
And note that this can be obtained with a series of bit-wise operations:
Happy coding.