How Does One Adjust Brightness Using FastLED CRGB?

I'm still new and still learning, however, not everything I think I want to do is mentioned in a book.

Maybe I am not searching using the correct search words, but, I can't find an example of how to adjust a pixel's brightness using FastLED CRGB. I found something using CHSV but not GRGB.

I'm not talking about setting the brightness in the setup but changing the brightness in the loop as needed.

What I'm ultimately wanting to do is to reduce brightness up by holding pin 9 down and increasing brightness by holding pin 10 down. But right now, I'm trying to figure out the best way to change brightness in the loop function.

Please help with your suggestions.

Here is my test program that does work (sort of) but using CHSV .

#include "FastLED.h"
#include <SPI.h>
#define LED_TYPE WS2812B    // Type of RGB LEDs
#define DATA_PIN      8    // LED data pin on the Arduino UNO
#define COLOR_ORDER GRB    // RGB -GRB // sequence of colors in data streem vs RGB GRB
#define NUM_LEDS     20    // 144 LEDs numbered [0 - 143]
#define MAX_BRIGHT  250    // brightness range is 0=off to 255= bright
 
CRGB leds[NUM_LEDS];

void setup()
{
  Serial.begin(9600);
  randomSeed(analogRead(0));
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  delay(3000);
  pinMode(DATA_PIN, OUTPUT);       // if using the prop shield this is required
  digitalWrite(DATA_PIN, HIGH);  
  CRGB leds(0,0,0);                // Turns off all LEDs
  FastLED.show();                  // if using the prop shield this is required
  delay(1000);                        //  Gives time to execute
}

void loop() 
{
  static uint8_t hue = 0;
  for(int i = 0; i < NUM_LEDS;   i++) 
  {
    for(int j = 0; j < MAX_BRIGHT; j++) {
      fill_solid(leds, NUM_LEDS, CHSV(hue++,255,j));    // light up whole strip  
      leds[i] = CHSV(hue++, 255, j);                    // Set the i'th led to red 
      FastLED.show();     // Show the leds
      delay(75);
    }
  delay(150);
  }
}

A lower value (0 to 255) for the color or colors means shorter time ON resulting in dimmer color. This value is not linear from color to color.

What does that mean?

What is the problem with that?

FastLED has a global brightness control ability.

If you mean to change the entire strip, use

         FastLED.setBrightness(howBright);    

just before

         FastLED.show();     // Show the leds

which would also be a perfect place to

   if (digitalRead(brighterButton) == LOW) howBright++;

and similarly for dimmerButton, the pin your other button is on. Here I assume you have wired the buttons to ground and use INPUT_PULLUP as the pin mode in setup().

After checking both switches, make sure howBright is between including 0 .. 255.

a7

Alto,

I want to change one specific LED's brightness at a time when I select hold down a specific pin.

I may be wrong here, but, to get specific colors, in a GRB WS2812, using CRGB the first of the 3 numbers is for different shades of green, the next number is for different shades of red and the last number is for different shades of blue. Using a combination of the 3 numbers gives the different colors and shades. But isn't there a way to send a 4th number to FastLED for just brightness, where FastLED does the math and changes the first 3 to give the same color but just less or more bright?

By using CHSV I seem to be loosing many of the many colors that can be created. Using 3 numbers from 0 to 255 gives many more combinations, where in CHSV is just i number from 0 to 255.

Again, I want FastLED to do the math to give the same color (I know that it is not linear, that is why I wanted FastLED to do it) when I ask for a brightness to one single LED.

setBrightness should be there, according to kewords.txt in the FastLED library folder. When I want a quick hint about features in a library, it's often illuminating (!) to look at the keywords for clues.

No. See post #2.

xfpd

8hpost #7

No. See post #2.

OK. Clear enough. I was hoping there was a way around . I can live with CHSV if it is the only to go.

Thanks all.

These two, Anas Kuzechie, ten-minutes videos describe low-level access and constructing a library for the WS2812. They give more information than I ever could about the low-level programming of the WS2812.

All,

I was able to find and test dimming specific LEDs in a WS2812 string of LEDs.

Below is my code and a link to where I found the information.

//  URL where I found this Info;  https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors
//  Look down the page to https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors


#include <FastLED.h>

#define LED_DT         8
#define COLOR_ORDER  GRB
#define LED_TYPE  WS2812
#define NUM_LEDS      10
#define dt           500
uint8_t max_bright = 155;
struct CRGB leds[NUM_LEDS];

void setup() {
  delay (1000);
  LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(max_bright);
}

void loop() {

for (int i = 0; i <= NUM_LEDS; i++) {
  leds[i].setHue(130); //  Sets color
  FastLED.show();
  for (int j = 4; j <= 6; j++) {
      // Reduce color to 75% (192/256ths) of its previous value
      // using "video" scaling, meaning: never fading to full black
     leds[j].nscale8_video( 192);  // Dimms color on LEDs 4, 5 & 6 starting fron 0
     FastLED.show();
  }
  delay(dt);
}
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.