Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

NEOPIXEL brightness control
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: NEOPIXEL brightness control

by chargerdude70 on Wed Aug 19, 2015 12:03 pm

Thank you Rick for your support and responses to this thread. For the life of me I can not get my code to function as intended so I went as simple with it as possible and still can't. I have added what I thought were the necessary items to the library that were posted on the fist page of this thread. My intentions are to have a theater chase with a variable fade as well as color choice. But I can not get a simple "on/off" to work while being variable. Could you please assist?

THIS CODE DOES NOT WORK

Code: Select all | TOGGLE FULL SIZE
//Mandatory items to make NEOPIXELS function
#include <Adafruit_NeoPixel.h>
const int ledNum = 9; // Number of LED's
const int ledPin = 0; // ATtiny85 LED signal output pin #
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(ledNum, ledPin);

//add ons

uint32_t Blue = pixels.Color(0, 0, 255);

void setup() {

  pixels.begin();
  pixels.show();
  pinMode(ledPin, OUTPUT);
 
}

// Set each pixel brightness individually
void setPixelColor( uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint16_t brightness) {
   pixels.setPixelColor(n, (brightness*r/255) , (brightness*g/255), (brightness*b/255));
}
   
void setPixelColor (uint16_t n, uint32_t c, uint16_t brightness);


void loop()
{
 
   pixels.setPixelColor(1, Blue, 250);
   pixels.show();
   delay(1000);
   pixels.setPixelColor(1, Blue, 125);
   pixels.show();
   delay(1000);
}


THIS CODE WORKS

Code: Select all | TOGGLE FULL SIZE
//Mandatory items to make NEOPIXELS function
 #include <Adafruit_NeoPixel.h>
const int ledNum = 9; // Number of LED's
const int ledPin = 0; // ATtiny85 LED signal output pin #
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(ledNum, ledPin);

//add ons

uint32_t Blue = pixels.Color(0, 0, 255);

void setup() {

  pixels.begin();
  pixels.show();
  pinMode(ledPin, OUTPUT);
 
}

// Set each pixel brightness individually using uint32_t
void setPixelColor( uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint16_t brightness) {
   pixels.setPixelColor(n, (brightness*r/255) , (brightness*g/255), (brightness*b/255));
}
   
void setPixelColor (uint16_t n, uint32_t c, uint16_t brightness){
 
}


void loop()
{
 
   pixels.setPixelColor(1, 0,0,255, 250);
   pixels.show();
   delay(1000);
   pixels.setPixelColor(1, 0,0,255, 125);
   pixels.show();
   delay(1000);
}

chargerdude70
 
Posts: 47
Joined: Thu Jan 02, 2014 11:49 am

Re: NEOPIXEL brightness control

by adafruit_support_rick on Wed Aug 19, 2015 5:02 pm

You must have added a new setPixelColor function to the library? Otherwise, your second set of code would not compile. You don't need the setPixelColor functions that you have in the sketch - you aren't calling those.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: NEOPIXEL brightness control

by chargerdude70 on Wed Aug 19, 2015 7:54 pm

I added this to .ccp

Code: Select all | TOGGLE FULL SIZE
// Set pixel brightness individually using seperate R,G,B components:
void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint16_t brightness) {
  setPixelColor(n, (brightness*r/255) , (brightness*g/255), (brightness*b/255));
}

// Set pixel brightness individually using a 'packed' 32-bit RGB color:
void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint32_t c, uint16_t brightness) {
}


and this to .h

Code: Select all | TOGGLE FULL SIZE
setPixelColor(uint16_t n, uint32_t c, uint16_t brightness),


Doing that

This code works as expected

Code: Select all | TOGGLE FULL SIZE
//Mandatory items to make NEOPIXELS function

#include <Adafruit_NeoPixel.h>
const int ledNum = 9; // Number of LED's
const int ledPin = 0; // ATtiny85 LED signal output pin #
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(ledNum, ledPin);
//uint32_t Blue = pixels.Color(0, 0, 255);

void setup() {

  pixels.begin();
  pixels.show();
  pinMode(ledPin, OUTPUT);
 
}

void loop()
{
 
   pixels.setPixelColor(1, 0,0,255, 250);
   pixels.show();
   delay(1000);
   pixels.setPixelColor(1, 0,0,255, 125);
   pixels.show();
   delay(1000);
}


This code compiles, but the pixel does light at all. Is there something wrong with the code I added to the .ccp and .h files?

Code: Select all | TOGGLE FULL SIZE
//Mandatory items to make NEOPIXELS function

#include <Adafruit_NeoPixel.h>
const int ledNum = 9; // Number of LED's
const int ledPin = 0; // ATtiny85 LED signal output pin #
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(ledNum, ledPin);
uint32_t Blue = pixels.Color(0, 0, 255);

void setup() {

  pixels.begin();
  pixels.show();
  pinMode(ledPin, OUTPUT);
 
}

void loop()
{
 
   pixels.setPixelColor(1, Blue, 250);
   pixels.show();
   delay(1000);
   pixels.setPixelColor(1, Blue, 125);
   pixels.show();
   delay(1000);
}

chargerdude70
 
Posts: 47
Joined: Thu Jan 02, 2014 11:49 am

Re: NEOPIXEL brightness control

by adafruit_support_rick on Thu Aug 20, 2015 12:25 pm

Yes - the function that takes three arguments is empty:
Code: Select all | TOGGLE FULL SIZE
// Set pixel brightness individually using a 'packed' 32-bit RGB color:
void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint32_t c, uint16_t brightness) {
}


It doesn't do anything. What you want to do is break out the three colors, and then call the other setPixelColor:

Code: Select all | TOGGLE FULL SIZE
void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint32_t c, uint16_t brightness) {
   uint8_t
      r = (uint8_t)(c >> 16),
      g = (uint8_t)(c >>  8),
      b = (uint8_t)c;
  setPixelColor(n, r, g, b, brightness);
}

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: NEOPIXEL brightness control

by chargerdude70 on Thu Aug 20, 2015 2:11 pm

Thank you very much Rick. I thought that line of code was missing something. But with me not knowing anything about programming, I wasn't sure. With code given by you, my test code works as expected. Again, thank you for your assistance and support on the forum.

chargerdude70
 
Posts: 47
Joined: Thu Jan 02, 2014 11:49 am

Re: NEOPIXEL brightness control

by adafruit_support_rick on Fri Aug 21, 2015 8:20 am

You're welcome!

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: NEOPIXEL brightness control

by chargerdude70 on Sun Aug 23, 2015 9:30 am

Rick, this code (chasefade) is why all the questions about fading lights with a separate variable. I wrote this code similar to another I use (using a "for" statement) as a "breathing" effect but the lights remain at the initial setting and won't increment.


lights dont fade
Code: Select all | TOGGLE FULL SIZE
//chaseFade....Make lights fade from low to high intensity while lighting one after another
#include <Adafruit_NeoPixel.h>
const int ledNum = 9; // Number of LED's
const int ledPin = 0; // ATtiny85 LED signal output pin #
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(ledNum, ledPin);
uint32_t Blue = pixels.Color(0, 0, 255);
uint16_t i, l;
#define DELAY 30 // Time delay between Pixels

void setup() {
  pixels.begin();
  pixels.show();
  pinMode(ledPin, OUTPUT);
}

// chaseFade
void loop() {
  int chase = 0;
  for (chase; chase < 5; chase++) {
    for (l = 28; l < 255; l = l+28) {
      for (i = 0; i < ledNum; i++) {
        pixels.setPixelColor(i, Blue, l);
        pixels.show();
        delay(DELAY);
      }
      for (i = 0; i < ledNum; i++) {
        pixels.setPixelColor(i, 0, 0, 0);
        pixels.show();
      }
      delay(1000);
    }
  }
}


lights do fade

Code: Select all | TOGGLE FULL SIZE
 // Breathing effect

    for(breathIng; breathIng < 5; breathIng ++){
      for(j = 0; j < 254; j=j+2) {
        for(i=0; i<pixels.numPixels(); i++) {
          pixels.setPixelColor(i, pixels.Color(0,j,0));
          pixels.show();
        }
      }

      for(j = 254; j > 0; j=j-2) {
        for(i=0; i<pixels.numPixels(); i++) {
          pixels.setPixelColor(i, pixels.Color(0,j,0));
          pixels.show();
        }
      }

      for(i=0; i<15; i++) {
        pixels.setPixelColor(i, 0,0,0);
        pixels.show();
      }
    }



    delay(500);

chargerdude70
 
Posts: 47
Joined: Thu Jan 02, 2014 11:49 am

Re: NEOPIXEL brightness control

by adafruit_support_rick on Sun Aug 23, 2015 11:21 am

I don't know. That should work. Your code looks OK. Does the new brightness function actually work? Have you tested it?

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: NEOPIXEL brightness control

by chargerdude70 on Sun Aug 23, 2015 4:13 pm

Yes...if I set up a simple on/off code for one or multiple leds...it will set a variable set color to a variable set brightness...just not in a "for" statement

chargerdude70
 
Posts: 47
Joined: Thu Jan 02, 2014 11:49 am

Re: NEOPIXEL brightness control

by chargerdude70 on Sun Aug 23, 2015 9:56 pm

Sorry Rick..I was wrong....the code does work. What it does is light the LEDs in sequence at a common intensity and increments the intensity the specified value with each new pass until full intensity has been achieved. What I am trying to do is get the LEDs to light in sequence while having them go up in intensity until full brightness in the same pass. Then repeat. I have tried to rearrange the code to best of my abilities but can not achieve my desired effect. Is this something possible? If so, can you assist?

chargerdude70
 
Posts: 47
Joined: Thu Jan 02, 2014 11:49 am

Re: NEOPIXEL brightness control

by adafruit_support_rick on Mon Aug 24, 2015 10:25 am

So I understand you just want one LED lit at any given time? You want to sequence through the LEDs one at a time, each time increasing the brightness?

Or do you want each LED to stay lit, and just get brighter on each pass?

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: NEOPIXEL brightness control

by chargerdude70 on Mon Aug 24, 2015 6:58 pm

Rick..the best to describe is the 16 led neopixle ring...starting at 0 and sequencing to 15...I would like the lights to light one at a time..the first being the dimist staying on till the last being the brightest...then repeat as desired...a chase with an incremental reverse fade so to speak...

chargerdude70
 
Posts: 47
Joined: Thu Jan 02, 2014 11:49 am

Re: NEOPIXEL brightness control

by adafruit_support_rick on Tue Aug 25, 2015 10:25 am

Does this do what you want?
Code: Select all | TOGGLE FULL SIZE
//chaseFade....Make lights fade from low to high intensity while lighting one after another
#include <Adafruit_NeoPixel.h>
const int ledNum = 9; // Number of LED's
const int ledPin = 0; // ATtiny85 LED signal output pin #
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(ledNum, ledPin);
uint32_t Blue = pixels.Color(0, 0, 255);
uint16_t i, l;
#define DELAY 30 // Time delay between Pixels

void setup() {
  pixels.begin();
  pixels.show();
  pinMode(ledPin, OUTPUT);
}

// chaseFade
void loop() {
  int chase = 0;
  uint8_t brightIncrement = 255 / pixels.numPixels();
  for (chase; chase < 5; chase++) {
    for (i = 0; i < ledNum; i++) {
      pixels.setPixelColor(i, Blue, ((i + 1) * brightIncrement));
      pixels.show();
      delay(DELAY);
    }
    for (i = 0; i < ledNum; i++) {
      pixels.setPixelColor(i, 0, 0, 0);
      pixels.show();
    }
    delay(1000);
  }
}

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: NEOPIXEL brightness control

by chargerdude70 on Tue Aug 25, 2015 7:26 pm

Yes sir Rick..Exactly...I wrote something kind of on the lines of yours but could not get it to work. Thank you for all your assistance.

chargerdude70
 
Posts: 47
Joined: Thu Jan 02, 2014 11:49 am

Re: NEOPIXEL brightness control

by adafruit_support_rick on Wed Aug 26, 2015 9:14 am

You're welcome!

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Please be positive and constructive with your questions and comments.