Unable to figure out why I can't dim or brighten Mark Kriegsman's wonderful Color

Unable to figure out why I can’t dim or brighten Mark Kriegsman’s wonderful Color Waves with Palettes. Here is a snippit of my Knob control code:

/////////////////////////////////////////////////
///////// Definitions here ///////////////////////
/////////////////////////////////////////////////

#define CHIPSET WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 130
#define MAX_BRIGHTNESS 180
#define MIN_BRIGHTNESS 20
const int brightnessInPin = A0;

void setup() {

/////////////////////////////////////////////////////
/////// knob setup here ////////////////
////////////////////////////////////////////////////

delay(3000); // 3 second delay for recovery

// tell FastLED about the LED strip configuration
FastLED.addLeds<CHIPSET, 7, COLOR_ORDER>(leds, UM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<CHIPSET, 8, COLOR_ORDER>leds,NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(MAX_BRIGHTNESS);
}

void loop(){

///////////////////////////////////////////////////////////
// Knob control here
///////////////////////////////////////////////////////////
int mappedValue = map(analogRead(brightnessInPin), 0, 1023, 0, 255);
FastLED.setBrightness(constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS));

FastLED.show();

What am I doing wrong here? Anyone please and thank you.

Did you try adding in some print statements to check:
The value read from A0,
The resulting mapped value,
The constrained value?

Also, when using map you should be able to change 0,255 to MIN_BRIGHTNESS, MAX_BRIGHTNESS, and then skip using constrain.

It works for me as is, however I noticed that you don’t have any Serial.println statements in there. Whenever I’m debugging code, they’re all over the place, and often find the stupidest of errors on my part.

In addition, I made the following changes (not that it didn’t already work):

#define brightnessInPin A0 // I prefer this
#define MIN_BRIGHTNESS 5 // 20 isn’t all the dull

Of course, I added Serial.begin(57600); in setup()

Finally, my loop had:

void loop() {
int mappedValue = map(analogRead(brightnessInPin), 0, 1023,
MIN_BRIGHTNESS, MAX_BRIGHTNESS);
FastLED.setBrightness(mappedValue);
fill_solid(leds,NUM_LEDS, 0xffffff);
Serial.println(mappedValue);
FastLED.show();
}

Oh, and always make a ‘test jig’ in order to test components of your sketch. In this case, I would have ripped out the fancy LED code and just added:

fill_solid(leds,NUM_LEDS, 0xffffff);

to test the functionality of the brightness mapping.

Thank you Marc Miller and Andrew Tuline. I found the problem: Broken cable feeding the A0 pin. Replaced and almost all is well. The only thing is that this display will NOT dim to zero. When I go to the lowest setting on the pot there is still a faint glow emiting from the LED’s.

Even if you set your MIN_BRIGHTNESS to 0??

yes. strange.

And what do your print statements show?

0 works for me… … it’s black. I used:

int mappedValue = map(analogRead(brightnessInPin), 0, 1023, MIN_BRIGHTNESS, MAX_BRIGHTNESS);

Edit: Again, ‘test jigs’ with serial.println statements to isolate specific issues.

@Freddie_Olivas ​ Are you still using constrain? If so, even if your MIN_BRIGHTNESS is set to 0, if your pot is reading something slightly above 0 for some reason then that’s what will get passed to setBrightness.

I must be an idiot but I don’t know what 0xffffff means as in the above statement:
fill_solid(leds,NUM_LEDS,0xffffff);
Can someone enlighten me please?

It’s probably just formatting you haven’t seen before @Freddie_Olivas . That’s a color specified as a Hex value.

You could set the color Blue for example using any of these formats:
leds[i] = CRGB::Blue;
leds[i] = CRGB(0,0,255);
leds[i] = CHSV(160,255,255);
leds[i] = 0x0000FF;

Scroll down to see many examples:

Freddie… that is HEX code for Full White… r=ff=255, g=ff=255, b=ff=255…

Thank you John Sullivan.