Hi
I'm running a Arduino Mega 2560 with 3 D (1.5V) batteries in series, which is wired to power 5 Neopixel LED strips and the arduino. They are all in parallel to the power. When the arduino is powered by a USB cable to my computer, the code runs fine.
However, when I detach my computer, hook up the power to the arduino, the code will run for a bit then freeze. It runs for an inconsistent number of the numLoops loop - anywhere from 2-12 before freezing. Once turned off and back on again it'll start running for a bit then freeze. Is this a code or hardware issue?
Help appreciated. I can also draw a circuit diagram if it's helpful/a hardware issue.
#include "FastLED.h"
#define PIN 6
#define PINouter 13
#define PINinner 11
#define PINbottom 7
#define PINtop 2
#define PINcenter 4
#define numOuter 81
#define numInner 64
#define numBottom 46
#define numTop 45
#define numCenter 17
#define numStrips 5
CRGB LED[numStrips][numOuter]; //outer
uint16_t stripSizeArray[] = {numOuter, numInner, numBottom, numCenter, numTop};
void setup() {
FastLED.addLeds<NEOPIXEL, 13>(LED[0], numOuter);
FastLED.addLeds<NEOPIXEL, 11>(LED[1], numInner);
FastLED.addLeds<NEOPIXEL, 7>(LED[2], numBottom);
FastLED.addLeds<NEOPIXEL, 4>(LED[3], numCenter);
FastLED.addLeds<NEOPIXEL, 2>(LED[4], numTop);
}
void loop() {
walkingPokeBall(10);
}
//Lights up a pokeball, with two pixels bouncing on the outer rim.
void walkingPokeBall(uint32_t wait){
// fill the pokeball with base red and white.
for(int numLoops = 0; numLoops < 20; numLoops++) {
fill_solid( (LED[4]), numTop, CHSV(0,255,255));
fill_solid( (LED[2]), numBottom, CHSV(255,0,100));
fill_solid( (LED[3]), numCenter, CHSV(255,0,150));
fill_solid( (LED[1]), numInner, CHSV(255,0,50));
for(uint8_t i=16; i<49;i++){
LED[1][i] = CHSV(0,255,50); // use less bright red on the inner outline.
}
//the next section sets the bouncing pixels across the outer rims
for(int i = 0; i < 38; i++) {
// set our current dot to red
if (i <20){
LED[0][20-i] = CRGB::White;
LED[0][20-i-1] = CRGB::White;
LED[0][20+i] = CRGB::Red;
LED[0][20+i+1] = CRGB::Red;
}
else {
LED[0][100-i] = CRGB::White;
LED[0][20+i] = CRGB::Red;
LED[0][100-i-1] = CRGB::White;
LED[0][20+i+1] = CRGB::Red;
}
FastLED.show();
delay(wait);
// turn off the pixel.
if (i <20){
LED[0][20-i] = CRGB::Black;
LED[0][20+i] = CRGB::Black;
LED[0][20-i-1] = CRGB::Black;
LED[0][20+i+1] = CRGB::Black;
}
else {
LED[0][100-i] = CRGB::Black;
LED[0][20+i] = CRGB::Black;
LED[0][100-i-1] = CRGB::Black;
LED[0][20+i+1] = CRGB::Black;
}
}
// make the pixel go back the other way.
for(uint8_t i = 0; i < 40; i++) {
if (i <20){
LED[0][60+i] = CRGB::White;
LED[0][59-i] = CRGB::Red;
LED[0][60+i+1] = CRGB::White;
LED[0][59-i-1] = CRGB::Red;
}
else {
LED[0][i-20] = CRGB::White;
LED[0][59-i] = CRGB::Red;
LED[0][i-20-1] = CRGB::White;
LED[0][59-i-1] = CRGB::Red;
}
FastLED.show();
delay(wait);
// turn off the pixel.
if (i <20){
LED[0][60+i] = CRGB::Black;
LED[0][59-i] = CRGB::Black;
LED[0][60+i+1] = CRGB::Black;
LED[0][59-i-1] = CRGB::Black;
}
else {
LED[0][59-i] = CRGB::Black;
LED[0][i-20] = CRGB::Black;
LED[0][i-20-1] = CRGB::Black;
LED[0][59-i-1] = CRGB::Black;
}
}
}
}