Here is all the code.
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, 6, NEO_GRB + NEO_KHZ800);
const byte PIR = 2; // motion detector input pin
byte senseMotion = 0; // variable to hold current state of motion detector
int buttonPIN = 4;
int val = 0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(PIR, INPUT);
pinMode(buttonPIN, INPUT);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void myCrap(uint32_t c, uint8_t wait) {
for (uint16_t k = 0; k < strip.numPixels(); k++) {
strip.setPixelColor(2 * k, c);
strip.show();
delay(wait);
}
}
void myCrap2(uint32_t c, uint8_t wait) {
for (uint16_t k = 0; k < strip.numPixels(); k++) {
strip.setPixelColor((2 * k + 1), c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// Chase one dot down the full strip.
void colorChase(uint32_t c, uint8_t wait) {
int i;
for (i = 0; i < strip.numPixels(); i++) strip.setPixelColor(i, 0);
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
strip.setPixelColor(i, 0);
delay(wait);
}
strip.show();
}
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
// KITT Effect
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
int i, j, pos, dir;
pos = 0;
dir = 1;
for (i = 0; i < ((strip.numPixels() - 1) * 8); i++) {
// Draw 5 pixels centered on pos. setPixelColor() will clip
strip.setPixelColor(pos - 2, strip.Color(r / 4, g / 4, b / 4));
strip.setPixelColor(pos - 1, strip.Color(r / 2, g / 2, b / 2));
strip.setPixelColor(pos, strip.Color(r, g, b));
strip.setPixelColor(pos + 1, strip.Color(r / 2, g / 2, b / 2));
strip.setPixelColor(pos + 2, strip.Color(r / 4, g / 4, b / 4));
strip.show();
delay(wait);
for (j = -2; j <= 2; j++)
strip.setPixelColor(pos + j, strip.Color(0, 0, 0));
pos += dir;
if (pos < 0) {
pos = 1;
dir = -dir;
} else if (pos >= strip.numPixels()) {
pos = strip.numPixels() - 2;
dir = -dir;
}
}
}
void loop() {
senseMotion = digitalRead(PIR);
if (senseMotion == HIGH) { // Tells lights to turn on
scanner(127,0,127, 15); //Tells what animation for the lights to play
strip.show(); // Initialize all pixels to 'off'
delay(100);
} else {
val = digitalRead(buttonPIN);
if (val == HIGH) {
strip.Color(0,0,0);
strip.show();
}
}
}
//Monocramatic Effect Sequence
//colorChase(strip.Color(127, 0, 127), 10); // Violet
//colorWipe(strip.Color(127, 0, 127), 10); // Violet
//myCrap(strip.Color(127,0,127),10); //Violet
//scanner(127,0,127, 15); // Violet
//myCrap2(strip.Color(0,0,0),10); // Off
//wave(strip.Color(127,0,127), 2, 40); // Violet
//rainbow(20);
//rainbowCycle(20);