Rumblegram:
Bulldog, I upgraded to a 3 amp power source behind my string but that second code of yours still isn't working. I'm going to try it with another string of NEOpixels tomorrow and see if something isn't fried. Any other ideas of what I should troubleshoot? Pins? Library install?
BTW that setBrightness() is pretty handy with your first code so I imagine it will be perfect when I get your second code with the set colors working. Thanks
- Check that you have the correct local settings for your RGB setup, mine is different:
(LED_COUNT, PIN, NEO_RGB + NEO_KHZ800);
- try it with 10 or 20 pixels using he same string:
#define LED_COUNT 50
-
verify your ledcount nd pin are correct.
-
comment out white here
uint32_t colors[] = {
0x00FF0000, // Red
0x0000FF00, // Green
0x000000FF, // Blue
//0x00FFFFFF, // White //<<<<<<, comment this out
};
I tested this... it works.
here it is again, in case there is an error above:
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define LED_COUNT 50
const int buttonPin = 2;
uint32_t colors[] = {
0x00FF0000, // Red
0x0000FF00, // Green
0x000000FF, // Blue
0x00FFFFFF, // White
};
class BlinkyPixel : public Adafruit_NeoPixel {
public:
BlinkyPixel(int numLeds, int pin, int type) : (numLeds, pin, type)
{
timer = new Timer[numLeds];
};
void update(void);
void init(int brightness);
void init(void);
private:
struct Timer{
uint32_t nextUpdateMillis;
bool state;
};
Timer* timer;
};
void BlinkyPixel::init(int brightness)
{
begin();
setBrightness(brightness);
show();
randomSeed(analogRead(A0));
for (size_t i = 0; i < numPixels(); i++)
{
timer[i].state = random(2);
timer[i].state? setPixelColor(i,colors[random(sizeof(colors)/sizeof(uint32_t))]) : setPixelColor(i, 0, 0, 0);
//timer[i].state? setPixelColor(i, random(0x00FFFFFF)) : setPixelColor(i, 0, 0, 0);
//timer[i].state? setPixelColor(i,random(0xFF), random(0xFF), random(0xFF)) : setPixelColor(i, 0, 0, 0);
timer[i].nextUpdateMillis = millis() + random(1000);
}
show();
}
void BlinkyPixel::init(void)
{
begin();
show();
randomSeed(analogRead(A0));
for (size_t i = 0; i < numPixels(); i++)
{
timer[i].state = random(2);
timer[i].state? setPixelColor(i,colors[random(sizeof(colors)/sizeof(uint32_t))]) : setPixelColor(i, 0, 0, 0);
//timer[i].state? setPixelColor(i, random(0x00FFFFFF)) : setPixelColor(i, 0, 0, 0);
//timer[i].state? setPixelColor(i,random(0xFF), random(0xFF), random(0xFF)) : setPixelColor(i, 0, 0, 0);
timer[i].nextUpdateMillis = millis() + random(1000);
}
show();
}
void BlinkyPixel::update(void)
{
bool doUpdate = false;
for (size_t i = 0; i < numPixels(); i++)
{
doUpdate = true;
if (millis() >= timer[i].nextUpdateMillis)
{
if (timer[i].state)
{
setPixelColor(i, 0, 0, 0);
}
else
{
setPixelColor(i,colors[random(sizeof(colors)/sizeof(uint32_t))]);
//setPixelColor(i, random(0x00FFFFFF));
//setPixelColor(i, random(0xFF), random(0xFF), random(0xFF));
}
timer[i].state = !timer[i].state;
timer[i].nextUpdateMillis = millis() + random(100, 1000);
}
}
if(doUpdate)
{
show();
}
}
BlinkyPixel strip(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
// Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
strip.init(255);
}
void loop()
{
static bool state = true;
if (state)
{
strip.update();
}
if (pressed(buttonPin))
{
state = !state;
if (!state)
{
for (size_t i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, 0, 0, 0);
}
strip.show();
}
else
{
strip.init();
}
}
}
bool pressed(int pin)
{
static uint32_t lastPressMillis = 0;
bool lastState = HIGH;
const uint16_t debounceTime = 50;
int currentState = digitalRead(pin);
if (currentState != lastState and millis() - lastPressMillis > debounceTime)
{
lastState = currentState;
if (currentState == LOW)
{
lastPressMillis = millis();
// Serial.println(F("pressed"));
return true;
}
}
return false;
}
I added a an overload of init() where you can add the brightness....