#include <Adafruit_NeoPixel.h>
#define STRIP1_COUNT 60
#define STRIP1_PIN 6
#define STRIP2_COUNT 60
#define STRIP2_PIN 7
#define RING_COUNT 16
#define RING_PIN 5
#define PIR1_PIN A0
#define PIR2_PIN 2
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(STRIP1_COUNT, STRIP1_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(STRIP2_COUNT, STRIP2_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ring = Adafruit_NeoPixel(RING_COUNT, RING_PIN, NEO_GRB + NEO_KHZ800);
int pir1Pin = A0;
int pir2Pin = 2;
int strip1Pin = 7;
int strip2Pin = 6;
int ringPin = 5;
boolean oldState = LOW;
int mode = 0; // Currently-active animatin mode, 0-9
int j=-1; // extra state variable for some modes
void setup() {
Serial.begin(115200);
pinMode(pir1Pin, INPUT);
pinMode(pir2Pin, INPUT);
pinMode(strip1Pin, OUTPUT);
pinMode(strip2Pin, OUTPUT);
pinMode(ringPin, OUTPUT);
strip1.begin();
strip1.show(); // Initialize all pixels to 'off'
strip2.begin();
strip2.show(); // Initialize all pixels to 'off'
ring.begin();
ring.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get Current sensor state.
boolean newState = digitalRead(PIR1_PIN);
// Check if state changed from low to high (sensor trigger)
if ((newState == HIGH) && (oldState == LOW)) {
// Short Delay to debounce sensor.
delay(20);
// Check if sensor is still high after debounce.
newState = digitalRead(PIR1_PIN);
if (newState == HIGH) {
if (++mode > 6) mode = 0;
}
}
// set the last-read sensor state to the old state.
oldState = newState;
// Manage the LED state bassed on mode
switch (mode) {
case 0:
strip1.show();
strip2.show();
mode = 2;
break;
case 2: // idle in off
break;
case 3:
colorWipe(strip1.Color( 0, 0, 255), 10); //Blue
colorWipe(strip2.Color( 0, 0, 255), 10); //Blue
mode = 4;
break;
default:
mode = 0;
break;
}
}
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
// Hue of first pixel runs 5 complete loops through the color wheel.
// Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
// means we'll make 5*65536/256 = 1280 passes through this loop:
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
// strip.rainbow() can take a single argument (first pixel hue) or
// optionally a few extras: number of rainbow repetitions (default 1),
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
ring.rainbow(firstPixelHue);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
ring.show(); // Update strip with new contents
delay(10); // Pause for a moment
}
for (int i=0; i < ring.numPixels(); i++)
{
ring.setPixelColor(i, 0); //turn every pixel off
}
ring.show();
}
// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip1.numPixels(); i++) { // For each pixel in strip...
for(int i=0; i<strip2.numPixels(); i++) { // For each pixel in strip...
strip1.setPixelColor(i, color); // Set pixel's color (in RAM)
strip2.setPixelColor(i, color); // Set pixel's color (in RAM)
strip1.show(); // Update strip to match
strip2.show(); // Update strip to match
delay(90); // Pause for a moment
}
for (int i=0; i < strip1.numPixels(); i++)
for (int i=0; i < strip2.numPixels(); i++)
{
strip1.setPixelColor(i, 0); //turn every pixel off
strip2.setPixelColor(i, 0); //turn every pixel off
}
strip1.show();
strip2.show();
}
}