0

What is 32-bit merged color value in Neopixel Library?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

What is 32-bit merged color value in Neopixel Library?

by orionlogic on Sat Dec 27, 2014 4:27 pm

Hi all,

I want to know what it means as "32-bit merged color value" when i use getPixelColor() from NeoPixel library. Can i change it, increment or decrement it? What kind of a data type is this?

Thanks.

orionlogic
 
Posts: 28
Joined: Mon Sep 08, 2014 2:52 pm

Re: What is 32-bit merged color value in Neopixel Library?

by franklin97355 on Sat Dec 27, 2014 8:10 pm

I'm not a coder but my understanding is it takes the three 8bit color values (R,G,B) and stuffs them into a single 32bit variable to send back to the program to do whatever it wanted the info for. You can manipulate the number but it is not as easy as incrementing by one, if you added one you would make the blue color one higher and that is all.

franklin97355
 
Posts: 18991
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: What is 32-bit merged color value in Neopixel Library?

by michaelmeissner on Sun Dec 28, 2014 1:11 am

The value is just:
Code: Select all | TOGGLE FULL SIZE
(red * 65536) + (green * 256) + blue
,

which is more typically expressed using bit shifting:
Code: Select all | TOGGLE FULL SIZE
(red << 16) + (green << 8) + blue
.

It is a convenient way to have a single value to encode 3 colors.

michaelmeissner
 
Posts: 1318
Joined: Wed Aug 29, 2012 12:40 am

Re: What is 32-bit merged color value in Neopixel Library?

by orionlogic on Sun Dec 28, 2014 5:58 am

Thanks both of you. I should try to understand bit shifting more.

orionlogic
 
Posts: 28
Joined: Mon Sep 08, 2014 2:52 pm

Re: What is 32-bit merged color value in Neopixel Library?

by splatten on Sun Dec 28, 2014 7:03 am

Only 24 bits are required, 8 bits for each colour, which gives you a colour 0 to 255, where 0 is back and 255 if full intensity, anything inbetween is a shade of that colour, for example 128 is half the intensity of 255.

Each bit in the colour is encoded where:
bit0 = 1
bit1 = 2
bit2 = 4
bit3 = 8
bit4 = 16
bit5 = 32
bit6 = 64
bit7 = 128

So when the bit pattern is 0 0 0 0 1 0 1 0, this corresponses to bit1 = 1 = 2, bit3 = 1 = 8, 2 + 8 = 10, if you shift this left then it becomes 0 0 0 1 0 1 0 0, now bit4 = 1 = 16 and bit2 = 1 = 4, 16 + 4 = 20. 0 comes on from the left and anything in bit7 falls off, unless you are shifting in a larger data type. Where you would extend the number of bits according to the size of the data type.

splatten
 
Posts: 421
Joined: Mon Mar 17, 2014 3:08 pm
Location: United Kingdom, Norwich

Please be positive and constructive with your questions and comments.