Have a small hiccup with my code for neopixels running off a trinket. I have the LEDs fade from green to red then back to green (every other one does the inverse). I'm not great at coding yet, and for the life of me, I can't seem to figure out why after one complete loop, the all turn off for about a second, then restart. Any pointers in the right direction would be helpful.
Here is my code:
Code: Select all
#include <Adafruit_NeoPixel.h>
#define PIN 1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);
uint16_t i;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
redgreen(200);
}
void redgreen(uint8_t wait) {
int x = 1; //use this to count up/down j
//the for j loop counts from 0 to 255, the when it reaches 256, counts back down
for (int j = 0; j > -1; j = j + x) {
for(i=0; i<10; i++) {
//This is even Pixels
if (i % 2) {
strip.setPixelColor(i, j, 256-j, 0);
strip.show();
}
//This is odd pixels
else {
strip.setPixelColor(i, 256-j, j, 0);
strip.show();
}
}
//strip.show();
if (j == 256) x = -1;
delay(wait);
}
}