//import good stuff to make the neopixel work
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
//define pin for neopixel
#define PIN 6
//initialize the neopixel object (number of LEDs, pin number, color mode)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(3);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
int line = 11;
lineLoop(line);
lineStatic(line);
lineResize(line);
lineStatic(line);
}
//creates a line that moves around the ring
void lineLoop(int length) {
for (int i = 0; i < 24; i++) {
for (int j = 0; j < length; j++) {
int light = i + j;
if (light > 23) {
light -= 24;
}
strip.setPixelColor(light, strip.Color(255, 0, 0));
}
strip.show();
delay(50);
for (int k = 0; k < 24; k++) {
strip.setPixelColor(k, 0);
}
strip.show();
}
}
//creates a line in place
void lineStatic(int length) {
for (int i = 0; i < length; i++) {
strip.setPixelColor(i, strip.Color(255, 0, 0));
}
strip.show();
delay(500);
}
//shrinks the line and expands it to its previous size
void lineResize(int length) {
for (int j = 0; j < 3; j++) {
//shrinks
for (int i = 0; i < ((length-1)/2); i++) {
strip.setPixelColor(i, 0);
strip.setPixelColor(length-1-i, 0);
strip.show();
delay(75);
}
//expands
for (int i = ((length-1)/2) - 1; i >= 0; i--) {
strip.setPixelColor(i, strip.Color(255, 0, 0));
strip.setPixelColor(length-1-i, strip.Color(255, 0, 0));
strip.show();
delay(16);
}
}
}
No comments:
Post a Comment