Hi all and sorry for the noob question!
I have an RGBW led strip that I'm driving with NeoPixel libraries, I can get a color value by reading a pixel with the getPixelColor() function: uint32_t myColor = strip.getPixelColor(i);
I have found I can extract R, G and B values in this way:
uint8_t red(uint32_t c) {
return (c >> 16);
}
uint8_t green(uint32_t c) {
return (c >> 8);
}
uint8_t blue(uint32_t c) {
return (c);
}
but if I try "return (c >> 24)" to get the white value, I obtain a value ten times higher, for example 2550 instead of 255...
How come?
ulipo:
but if I try "return (c >> 24)" to get the white value, I obtain a value ten times higher, for example 2550 instead of 255...
That should work. Post a short but complete sketch that demonstrates the problem, and the output you see on serial monitor.
I suspect the extra "0" is coming from some other part of your code. When using bit shifting and manipulation, the result is not likely to be wrong by a factor of 10. It's much more likely to be wrong by a factor of 2, 4, 8, 16...