I searched here and watched a few YouTube vids too but surprisingly didn't find anything...
Is there a handy function or some fairly clear math that would help me cycle LEDs on a WS2812B strip through just an 8-bit (256 color) palette choice a-la Windows 95, or "web colors"?
I'm using the Adafruit_NeoPixel.h library.
Many thanks in advance!
EDIT: After reading some of the example code on GitHub I'm thinking as a last resort maybe just to use ColorHSV() in increments of 256 and hit each choice with gamma32(). May test later, but still happy to hear of any other suggestions or pointers!
Are you trying to save memory? Simple math is R2G2B2, which would give 64 colors.
You can pick whatever subsets of colors to use that you want. However, you still need to send 24 bit color to the WS2812B. All libraries I know of also expect to get a buffer of 24 bit values, however, one could write code to buffer palette indexes, which are only expanded to 24 bits on transmission.
Web colors are 24 bit, so don't see what you are getting at there. Earlier versions of Windows supported color palettes, because that is how the graphics cards worked. Since graphics cards are now 32 bit and memory is cheap, color palettes are mostly not used I think.
The goal was to come up with an easier to select palette of colors that I'd be cycling through with a pushbutton or at some point perhaps a dial. Twiddling R/G/B or going through 65536 H selections would be a bit much. Even 256 is a bit exhausting, but, manageable. EDIT: I'm now using increments of 1024 for 64 selections and I think that's good enough now.
At the moment I'm using this [below] on a pushbutton, which is "good enough for government work". (Three variables because I need a brightness gradient). It has some of the envisioned palette missing because it uses the HSV mapping and just sticks 255 into S and then the brightness gradients into V. But it gives me pretty much all of the outer ring of the color wheel.
I'd be totally cool with an old-skool "basic colors" selection (~48 more or less) from early MS Windows but I think I'd have to build an array with the hue/sat/lum values and cycle through the array. I was just hoping maybe that particular wheel was already invented and tucked away in a corner or collecting dust in a shed someplace.
FYI I tried this code without gamma32() as well and it really screwed up the apparent brightness of the gradients so I put it back.
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
#define NUMPIXELS 1 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//-----------------------------------------------------------------------
void setup() {
Serial.begin(115200);
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
//-----------------------------------------------------------------------
void loop() {
pixels.clear(); // Set all pixel colors to 'off'
for (int j = 0; j < 256; j++) {
Serial.println(j);
for (int k = 0; k < 256; k++) {
//Serial.println(k);
for (int l = 0; l < 256; l++) {
// Serial.println(l);
//Serial.println(j);
for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(l, k, j));
pixels.show(); // Send the updated pixel colors to the hardware.
//delay(1); // Pause before next pass through loop
}
}
}
}
}