NeoPixel library not outputting correctly
Posted: 13 May 2022 01:42
I followed the schematic in the examples for the NeoPixels to invert the signal. I have them hooked up and can produce some colors on the NeoPixel strip, however, the colors are not associated with pixel 1, pixel 2 and so forth. They appear to overlap, perhaps having the wrong buffer length per pixel? I have 4, triple color NeoPixels and here is the example code I am using:
#include "ZUNO_NeoPixel.h"
#define MAX_PIXELS 4 // NB! Z-Uno can not control more than 25 WS2811 without harming RF communications
#define PIXEL_SIZE 3 // Three colors per pixel
#define BUFF_SIZE (MAX_PIXELS * PIXEL_SIZE)
byte pixel_buff[BUFF_SIZE];
NeoPixel pixels(pixel_buff, BUFF_SIZE);
void setup() {
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Set all pixel colors to 'off'
}
void loop() {
for(int i=0; i<254; i++) {
pixels.setPixelColor(1, pixels.Color(i, 0, 0));
delay(10);
pixels.show();
}
for(int i=0; i<254; i++) {
pixels.setPixelColor(1, pixels.Color(0, i, 0));
delay(10);
pixels.show();
}
for(int i=0; i<254; i++) {
pixels.setPixelColor(1, pixels.Color(0, 0, i));
delay(10);
pixels.show();
}
pixels.clear();
delay(5000);
}
With this code, the second pixel on the strip goes red, then blue, and then the third pixel goes green when it should only be modifying the second pixel. Also, the pixels.clear(); doesn't clear the first pixel if a color has been put on that. Is there something I can change or some other place to define the buffer?
#include "ZUNO_NeoPixel.h"
#define MAX_PIXELS 4 // NB! Z-Uno can not control more than 25 WS2811 without harming RF communications
#define PIXEL_SIZE 3 // Three colors per pixel
#define BUFF_SIZE (MAX_PIXELS * PIXEL_SIZE)
byte pixel_buff[BUFF_SIZE];
NeoPixel pixels(pixel_buff, BUFF_SIZE);
void setup() {
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Set all pixel colors to 'off'
}
void loop() {
for(int i=0; i<254; i++) {
pixels.setPixelColor(1, pixels.Color(i, 0, 0));
delay(10);
pixels.show();
}
for(int i=0; i<254; i++) {
pixels.setPixelColor(1, pixels.Color(0, i, 0));
delay(10);
pixels.show();
}
for(int i=0; i<254; i++) {
pixels.setPixelColor(1, pixels.Color(0, 0, i));
delay(10);
pixels.show();
}
pixels.clear();
delay(5000);
}
With this code, the second pixel on the strip goes red, then blue, and then the third pixel goes green when it should only be modifying the second pixel. Also, the pixels.clear(); doesn't clear the first pixel if a color has been put on that. Is there something I can change or some other place to define the buffer?