I've reduced the project to the test program below. All that it does is init one string (160 LEDs), then runs one lit LED up the string. Current draw is negligible. Also in loop() is an analogRead(). Both are timed using millis(), LED "motion" every 30 mS, analog read every 20.
Increasing analogRead() frequency increases the number of glitches. The green LED (#0) lit is a glitch. If the analogRead() is commented out, it does not happen. If the read is done once per second, you often can't see it at all.
Anyone have any insight here?
Code: Select all
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_NeoPXL8.h>
// NEOPXL8 board on Metro M4 pins.
//
int8_t NEO_PINS[8] = { 7, 6, 5, 4, 3, 2, 10, 11 };
const int LEDS = 160;
Adafruit_NeoPXL8 leds (LEDS, NEO_PINS, NEO_GRB);
long T1, T2;
void setup () {
leds.begin();
leds.setBrightness (128);
for (int i= 0; i < LEDS; i++) {
leds.setPixelColor (i, 64, 64, 64);
}
leds.show();
T1= millis() + 31;
T2= millis() + 7;
}
void loop () {
static int p;
// read analog, spurious LEDs light...
//
if (millis() > T2) {
T2= millis() + 3;
analogRead (A0);
}
// Walk a single lit LED up the string.
//
if (millis() < T1) return;
T1= millis() + 31;
leds.setPixelColor (p, 0);
if (++p >= LEDS) p= 0;
leds.setPixelColor (p, 64, 128, 64);
leds.show();
}