1m neopixel strip coding help

Hello, I'm new to coding and electronics. I have a 1m 30 RGB LED light strip from Adafruit and have enjoyed playing with it with my Arduino Uno. I've made some simple animations have have gotten the results I expected. However, on my latest "animation" I'm not getting what I should be. The idea is to have a single LED start in the middle and go down the strip to the end and then stay lit. The next light after that follows suit and they continue stacking up on the ends. Everything went well for one side and then I fixed it for the other side. However, when I upload and run the sketch everything works fine for the first run through (well, except a lasting pixel staying lit at 0) but after the first run through the left side (15 to 29) starts behaving strangely. The lights won't stack (stay lit) but a single pixel may light and turn off when it should be turning on and staying on. I'm thinking perhaps I'm running out of memory. My understanding is the Mega is better for RGB LED strips because they have more memory. I'll have to wait until I can afford to purchase a Mega to verify if that's the issue. But, perhaps someone would be helpful enough to load this code to their RGB strip and see if they're getting the same results. I can possibly take a video of the issue I'm having if that helps. Again, I'm completely new to coding and electronics all together. So as for my code (I've not commented it yet or cleaned it up any), just have been trying to get the "animation" running correctly. Here is the entire sketch (I had it in a sketch with other animations but once I started experiencing the issue I tossed it into it's own sketch to cut down on memory usage but to no avail). Other sketches (the test sketch and some other sketches I've found online) work well and function as expected. Code is included below- thanks for reading and for any advice/help you're able to give. You can ignore the last bit at the end which I currently have commented out. It was just for controlling the right side (0-14) but I found I had to have a for loop that utilized both sides to run at the same time. What a learning experience this has been so far- but I'm loving it!

#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

int r = 0;
int x = 29;
int d = 30;
void setup() {
  
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}





void loop() {

pattern3();
}


void pattern3() {
   
     for (int z = 15, y = 15; z<x, y>r; z++, y--) {
      strip.setPixelColor(z, 0, 63, 0);
      strip.setPixelColor(y, 0, 63, 0);
     strip.show();delay(d);delay(d);
     strip.setPixelColor(z, 0, 0, 0);
    strip.setPixelColor(y, 0, 0, 0);
    strip.show();
  
   
      
   }
 strip.setPixelColor(r, 0, 63, 0);
 strip.setPixelColor(x, 0, 63, 0);
 strip.show();

 x--;
 r++;

 
 if (x<14) {
   x=29;
 }

 if (r>14) {
   r=0;
 }
 delay(d);
 
/*   
   for (int y = 14; y>r; y--) {
     strip.setPixelColor(y, 0, 63, 0);
     strip.show(); delay(d);delay(d);
     strip.setPixelColor(y, 0, 0, 0);
     strip.show();
   }

 strip.setPixelColor(r, 0, 63, 0);
 
 r++;
 if (r>=15) {
   r=0;
 }
 */
   }

Hi emiskilla. I don't have much time to play with it right now, but as far as the extra pixel lighting up, comment out the line below:

void pattern3() {
   
<snip>
   
      
   }
 strip.setPixelColor(r, 0, 63, 0);
// strip.setPixelColor(x, 0, 63, 0); [color=red]COMMENT OUT THIS LINE[/color]
 strip.show();

I'll try to get some time to play with it this weekend. I commented out the second part and have it running on my 60 pixel strip, and it works fine like that, as you said. Cool looking effect!

I'll let you know when I figure it out, unless someone else does before I get to it.

Edit: Some magic decoder ring needed to make the color tags work? :grin:

Sorry, I just realized this is a pretty old post. Let me know if you're still around and I'll work on it for you.

Bluzeman,

Yep this is definitely something I'm still working on. I haven't had much time lately to play around with my neopixel strip- too busy with work and too tired after work lol. But, this is an effect I'd like to have running smoothly. I'm going to try your suggestion of commenting out that line later tonight and I'll see. But, are you also having the same issue with the left side (for me 15-29)? I can't understand why it works perfectly for the first two cycles and then starts acting stupid. I'm no programmer so this is all learning for me. But I do appreciate your help!

I'm sure there are much more elegant ways to do this, but I've never been really good at trying to follow someone else's logic. Probably cause I'm so damn illogical. :smiley: But it seems to work. Try it out and see. All I did really was comment out the line I told you about yesterday, and added a variable for the other side that get's incremented along with the loop. And played with the numbers some. One thing to keep in mind is the first pixel is zero. So on a 30 pixel strip the max value is 29, not 30. So one must be careful when you choose equal to or greater than. And honestly, I'm not sure that was an issue, I just played with the numbers till it looked right.

Edit: I made the delay time much shorter so I didn't have to wait as long to see if it works, so you might want to change that back. It's been running for about a half hour now, and no glitches that I've seen.

#include <Adafruit_NeoPixel.h>

#define PIN 6
int direction=1;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800);





int r =0;
int x = 30;
int d = 10;

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}





void loop() {
  int b=15;
 
     for (int z = 14, y = 15; z<x, y>r; z++, y--) {
   
     
       
    //  strip.setPixelColor(z, 0, 63, 0);
    strip.setPixelColor(y, 0, 63, 0);
   

     strip.show();delay(d);delay(d);
      strip.setPixelColor(b, 0, 63, 0);
     strip.setPixelColor(z, 0, 0, 0);
     
     b++;
    
   
  strip.setPixelColor(y, 0, 0, 0);
    strip.show();


      
   }
 strip.setPixelColor(r, 0, 63, 0);
// strip.setPixelColor(x, 0, 63, 0);
 strip.show();

 x--;
 r++;

 
if (x<14) {
   x=29;
 }

 if (r>57) {
  r=0;
 }
 delay(d);
 
/*   
   for (int y = 14; y>r; y--) {
     strip.setPixelColor(y, 0, 63, 0);
     strip.show(); delay(d);delay(d);
     strip.setPixelColor(y, 0, 0, 0);
     strip.show();
   }

 strip.setPixelColor(r, 0, 63, 0);
 
 r++;
 if (r>=15) {
   r=0;
 }
 */
   }

Thanks Bluzeman! Works just like I wanted it to! I still have the two end pixels staying lit- but that's probably just an adjustment on a number somewhere. Thanks very much for taking your time and fixing it!! You're awesome!

You did all the work, I just tweaked it a little.

I saw the 2 pixels on the end, but I kind of liked how the wipe ended and left them there, wasn't sure if you intended it that way or not.

No, the two nagging pixels on the end aren't intentionally left on. But, there is always a work around for that. The next step for me is to implement the colorwheel so I can have each pixel be a different color. But, I haven't attempted to use the colorwheel yet cause in the test strip code it looked a little complicated for me lol. So I'm sure in time I'll be asking for help with it if I'm not able to comprehend it lol. But, I appreciate your help in getting my code fixed!