Sorry if this seems like a dumb question to some buy my first go at this. My goal is to have a trigger run one pattern on a LED strip and then if interrupted by the other trigger it will stop patter on LED strip and run pattern on LED ring. I have gotten the patterns to play with triggers but I'm confused on how to make the 2nd trigger interrupt the first pattern. Here is my code so far
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, 6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(60, 6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ring = Adafruit_NeoPixel(16, 5, NEO_GRB + NEO_KHZ800);
int pir1Pin = 2;
int pir2Pin = A2;
int led3Pin = 7;
int led1Pin = 6;
int led2Pin = 5;
void setup() {
pinMode(pir1Pin, INPUT);
pinMode(pir2Pin, INPUT);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip2.begin();
strip2.show(); // Initialize all pixels to 'of
ring.begin();
ring.show();
}
void loop() {
if(digitalRead(pir2Pin)==HIGH) {
colorWipe(strip.Color( 0, 0, 255), 10); // Blue
colorWipe(strip2.Color( 0, 0, 255), 10); // Blue
}
if(digitalRead(pir1Pin)==HIGH)
rainbow(5);
}
// 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();
}
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
void theaterChaseRainbow(int wait) {
int firstPixelHue = 0; // First pixel starts at red (hue 0)
for(int a=0; a<30; a++) { // Repeat 30 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in increments of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
// hue of pixel 'c' is offset by an amount to make one full
// revolution of the color wheel (range 65536) along the length
// of the strip (strip.numPixels() steps):
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(2); // Pause for a moment
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
}
for (int i=0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, 0); //turn every pixel off
}
strip.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<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(50); // Pause for a moment
}
for (int i=0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, 0); //turn every pixel off
}
strip.show();
}