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;
}
*/
}