Page 4 of 8
Re: NEOPIXEL brightness control
Posted: Wed Aug 19, 2015 12:03 pm
by chargerdude70
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
//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
//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);
}
Re: NEOPIXEL brightness control
Posted: Wed Aug 19, 2015 5:02 pm
by adafruit_support_rick
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.
Re: NEOPIXEL brightness control
Posted: Wed Aug 19, 2015 7:54 pm
by chargerdude70
I added this to .ccp
Code: Select all
// 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
setPixelColor(uint16_t n, uint32_t c, uint16_t brightness),
Doing that
This code works as expected
Code: Select all
//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
//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);
}
Re: NEOPIXEL brightness control
Posted: Thu Aug 20, 2015 12:25 pm
by adafruit_support_rick
Yes - the function that takes three arguments is empty:
Code: Select all
// 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
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);
}
Re: NEOPIXEL brightness control
Posted: Thu Aug 20, 2015 2:11 pm
by chargerdude70
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.
Re: NEOPIXEL brightness control
Posted: Fri Aug 21, 2015 8:20 am
by adafruit_support_rick
You're welcome!
Re: NEOPIXEL brightness control
Posted: Sun Aug 23, 2015 9:30 am
by chargerdude70
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
//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
// 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);
Re: NEOPIXEL brightness control
Posted: Sun Aug 23, 2015 11:21 am
by adafruit_support_rick
I don't know. That should work. Your code looks OK. Does the new brightness function actually work? Have you tested it?
Re: NEOPIXEL brightness control
Posted: Sun Aug 23, 2015 4:13 pm
by chargerdude70
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
Re: NEOPIXEL brightness control
Posted: Sun Aug 23, 2015 9:56 pm
by chargerdude70
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?
Re: NEOPIXEL brightness control
Posted: Mon Aug 24, 2015 10:25 am
by adafruit_support_rick
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?
Re: NEOPIXEL brightness control
Posted: Mon Aug 24, 2015 6:58 pm
by chargerdude70
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...
Re: NEOPIXEL brightness control
Posted: Tue Aug 25, 2015 10:25 am
by adafruit_support_rick
Does this do what you want?
Code: Select all
//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);
}
}
Re: NEOPIXEL brightness control
Posted: Tue Aug 25, 2015 7:26 pm
by chargerdude70
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.
Re: NEOPIXEL brightness control
Posted: Wed Aug 26, 2015 9:14 am
by adafruit_support_rick
You're welcome!