Weird Neopixel behavior.

Aside from powering the 8 LED strip from the UNO, I’ve tried to follow the adafruit best practices guide, 330ohm resistor on the data wire (pin 6), and a 470uf (biggest I have) Capacitor across the ground and 5v. I have also run the strandtest example that comes with the library, and it functions as expected. Other sketches I’ve written also work fine with this strip.

Intent is all 8 LED’s fade from Red to Green to Blue and back to Red, showing a rainbow. The Serial monitor is showing the correct values as intended.

What is happening though, is initially the strip is dark, until it reaches bright Green, the pixels then light up from 0-7 with a visible delay (it’s on the breadboard vertically, looks like a strongman sledgehammer carnival game when the green lights up). It then fades from Green to Blue and into Red as intended, but it then stays on bright Red until it reaches bright green, again with the same behavior changing the LED’s, and continues normally from there.

Any ideas? (Also feel free to pick apart the code in general, I can only learn from it)

#include <Adafruit_NeoPixel.h>

template<class T> inline Print &operator <<(Print &obj, T arg) 
{ 
  obj.print(arg); 
  return obj; 
}

const int pin = 6;

int newcol[3];

Adafruit_NeoPixel pix =Adafruit_NeoPixel(8, pin, NEO_GRB + NEO_KHZ800);


void setup()
{
  pix.begin();
  pix.show();
  Serial.begin(9600);
}

void loop()
{
  for (int i = 0; i <765; i++) //Cycle through the color wheel
  {
    ColorWheel(newcol, i);
    for(int x=0; x<8; x++) //assign all pixels on the strip to the same color
    {
      pix.setPixelColor(x, newcol[1], newcol[2], newcol[3]);
    }
    pix.show();
    Serial << "\n" << i << "  " << newcol[1] << "  " << newcol[2] << "  " << newcol[3] ;

    //delay(10);
  }
}



void ColorWheel(int* ptr, int wpos)
{

  if (wpos > 764 || wpos < 0) // Bright white if out of bounds
  {
    ptr[1]=255;
    ptr[2]=255;
    ptr[3]=255;
  }
  else if(wpos <=255)
  {
    ptr[1]=255-wpos;
    ptr[2]=wpos;
    ptr[3]=0;
  }
  else if (wpos > 255 && wpos < 511)
  {
    ptr[1]=0;
    ptr[2]=510-wpos;
    ptr[3]=wpos-255;
  }
  else
  {
    ptr[1]= wpos - 510;
    ptr[2]= 0;
    ptr[3]=765-wpos;
  }

}

Your newcol array is length 3, but you access past the end. Valid indexes are 0..N-1 for an N-element array.

You might want to use names for the indices anyway:

#define RED 0
#define GREEN 1
#define BLUE 2

then you can say

  newcol[RED]

and so forth...

Son of a… Figured it was something stupidly simple like that… Thanks!

Good idea with the defines.