WS2812b brightness problem

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Freakdoctor
 
Posts: 1
Joined: Wed Aug 14, 2019 11:53 am

WS2812b brightness problem

Post by Freakdoctor »

Hi all.

I have a little problem with adarfuit library. When my brithness reach 0 the leds stay off, so i have to set brithness and animations between 255 and 1.

Also for some colors like

Code: Select all

int MAGENTA[3] = {255, 0, 200};
in breath or blink animations the color becomes red or blue depending witch one has 255 value.

Somebody can explain to me where is my mistake?

Excuse my approximate english i'm french.
Thanks.
Yan.

Code: Select all

#include <Adafruit_NeoPixel.h>
#include <IRremote.h>

#define PIXEL_PIN 5
#define PIXEL_COUNT 14

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

int RECV_PIN = 10;

unsigned long lastCode;

int up = 5;
int down = 5;
int upperLimit = 255;
int lowerLimit = 1;
int brightness = 85;
int minBrightness = 20;

int fadeAmount = 1;
int interval = 10;
int fadebrightness = 50;
int sparkleUpperLimit;
unsigned long startMillisSparkle;

int flashInterval = 1000;
unsigned int flashLowerLimit = 1;
int flashUpperLimit;
int flashBrightness;
unsigned long startMillisFlash;

int RED[3] = {255, 0, 0};
int GREEN[3] = {0, 255, 0};
int BLUE[3] = {0, 0, 255};
int MAGENTA[3] = {255, 0, 200};
int ORANGE[3] = {255, 127, 0};
int CYAN[3] = {0, 255, 255};
int PINK[3] = {255, 0, 255};
int YELLOW[3] = {255, 255, 0};
int PURPLE[3] = {150, 0 , 255};
int WHITE[3] = {255, 255, 255};
int OFF[3] = {0, 0, 0};

bool sparkle;
bool flash;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();

  pixels.begin();
  colorChange(20, BLUE);
  pixels.setBrightness(85);
  //pixels.clear();
  startMillisSparkle = millis();
  sparkle = false;
  flash = false;
}

void loop()
{
  //IR Input
  if (irrecv.decode(&results)) {

    if (results.value == 0xFFFFFFFF)
    {
      results.value = lastCode;
    }

    if (results.value == 0xf710ef)
    {
      lastCode = results.value;
      colorChange(20, RED);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf7906f)
    {
      lastCode = results.value;
      colorChange(20, GREEN);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf750af)
    {
      lastCode = results.value;
      colorChange(20, BLUE);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf730cf)
    {
      lastCode = results.value;
      colorChange(20, MAGENTA);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf7b04f)
    {
      lastCode = results.value;
      colorChange(20, ORANGE);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf7708f)
    {
      lastCode = results.value;
      colorChange(20, CYAN);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf708f7)
    {
      lastCode = results.value;
      colorChange(20, PINK);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf78877)
    {
      lastCode = results.value;
      colorChange(20, YELLOW);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf748b7)
    {
      lastCode = results.value;
      colorChange(20, PURPLE);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf7c837)
    {
      lastCode = results.value;
      colorChange(20, WHITE);
      pixels.setBrightness(brightness);
      pixels.show();
    }

    if (results.value == 0xf740bf)
    {
      lastCode = results.value;
      colorChange(20, OFF);
    }

    if (results.value == 0xf700ff)
    {
      lastCode = results.value;
      increaseFunction();
      Serial.println("brightness= ");
      Serial.println(brightness);
    }

    if (results.value == 0xf7807f)
    {
      lastCode = results.value;
      decreaseFunction();
      Serial.println("brightness=  ");
      Serial.println(brightness);
    }

    if (results.value == 0xf728d7)
    {
      lastCode = results.value;
      flash = true;
    }

    if (results.value != 0xf728d7)
    {
      lastCode = results.value;
      flash = false;
    }

    if (results.value == 0xf7a857)
    {
      lastCode = results.value;
      sparkle = true;
      pixels.setBrightness(brightness);

    }

    if (results.value != 0xf7a857)
    {
      lastCode = results.value;
      sparkle = false;
      pixels.setBrightness(brightness);

    }

    irrecv.resume();

    Serial.println(results.value, HEX);
    

  }

  // Animation Sparkle
  if (sparkle)
  {
    sparkleUpperLimit = brightness;
    int aInterval = (255 / sparkleUpperLimit) * interval;
    
    if (millis() - startMillisSparkle  >= aInterval) {
      fadebrightness = fadebrightness + fadeAmount;
      startMillisSparkle = millis();


      if (fadebrightness <= lowerLimit )
      {
        fadebrightness = lowerLimit;
        fadeAmount = -fadeAmount;
      }

      if (fadebrightness >= sparkleUpperLimit )
      {
        fadebrightness = sparkleUpperLimit;
        fadeAmount = -fadeAmount;
      }
      pixels.setBrightness(fadebrightness);
      pixels.show();
    }
  }

  //Animation Flash
  if (flash)
  {
    flashUpperLimit = brightness;

    if (millis() - startMillisFlash >= (flashInterval)) {
      startMillisFlash = millis();

      if (flashBrightness <= flashLowerLimit )
      {
        flashBrightness = flashUpperLimit;
      }

      else
      {
        flashBrightness = flashLowerLimit;
      }
      pixels.setBrightness(flashBrightness);
      pixels.show();
    }
  }
}


void increaseFunction() {

  brightness += up;
  if (brightness >= upperLimit) brightness = upperLimit;
  for (int i = 0; i < PIXEL_COUNT ; i++)
  {
    pixels.setBrightness(brightness);
  }
  pixels.show();
}

void decreaseFunction()
{
    brightness -= down;
    if (brightness <= lowerLimit) brightness = lowerLimit;
    for (int i = 0; i < PIXEL_COUNT ; i++)
    {
      pixels.setBrightness(brightness);
    }
    pixels.show();
  }

void colorChange(int delayTime, int COLOR[])
{
  for (int i = 0 ; i < PIXEL_COUNT ; i++)
  {
    pixels.setPixelColor(i, COLOR[0], COLOR[1], COLOR[2]);
    pixels.show();
    delay(delayTime);
  }
}

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: WS2812b brightness problem

Post by adafruit_support_carter »

I have a little problem with adarfuit library. When my brithness reach 0 the leds stay off, so i have to set brithness and animations between 255 and 1.
That's the intended behavior. 0 = off, 255 = max brightness.
in breath or blink animations the color becomes red or blue depending witch one has 255 value.
The three values are the red, green, blue levels. So by changing them, you are changing the color.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”