// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 9 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 40 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50 // Time (in milliseconds) to pause between pixels
#define BARLENGTH 10 // Length of moving bar
bool isFirstBarLength = 1; // whether first creating bar
int pixelIdx = 0;
int background[3] = {0, 0, 0};
int r = 16;
int g = 10;
int b = 10;
void setup() {
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
// The first NeoPixel in a strand is #0, second is 1, all the way up
// to the count of pixels minus one.
// for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
// // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255:
// pixels.setPixelColor(i, pixels.Color(200, 200, 200));
// pixels.show(); // Send the updated pixel colors to the hardware.
// delay(DELAYVAL); // Pause before next pass through loop
// }
if (isFirstBarLength) {
pixels.clear();
for (int i = 0; i < BARLENGTH; i++) {
pixels.setPixelColor(i, pixels.Color(r, g, b));
pixels.show();
pixelIdx++;
delay(DELAYVAL);
}
isFirstBarLength = 0;
}
bool powerOn = 1;
while (powerOn) {
pixels.setPixelColor(pixelIdx, pixels.Color(r, g, b));
pixels.show();
pixels.setPixelColor((pixelIdx - BARLENGTH), pixels.Color(background[0], background[1], background[2]));
pixels.show();
if (pixelIdx >= NUMPIXELS) {
pixels.setPixelColor(pixelIdx - NUMPIXELS, pixels.Color(r, g, b));
pixels.show();
if (pixelIdx >= (NUMPIXELS - 1) + BARLENGTH) {
powerOn = 0;
pixelIdx = BARLENGTH - 1;
}
}
pixelIdx++;
if (r > 10 && r < 160 && g == 10 && b == 10) {
r += 2;
}
if (r >= 160) {
r = 10;
g = 16;
}
if (g > 10 && g < 160 && r == 10 && b == 10) {
g += 2;
}
if (g >= 160) {
g = 10;
b = 16;
}
if (b > 10 && b < 160 && r == 10 && g == 10) {
b += 2;
}
if (b >= 160) {
b = 10;
r = 16;
}
delay(DELAYVAL);
}
}