#include "FastLED.h" #define PIR_1 4 #define PIR_2 5 #define LED_PIN 3 #define LED_TIME = 800 #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define NUM_LEDS 16 CRGB leds[NUM_LEDS]; enum PIR_STATUS {S_ONE, S_TWO, BOTH}; #define BRIGHTNESS 255 #define FRAMES_PER_SECOND 120 void setup() { // tell FastLED about the LED strip configuration FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); pinMode(PIR_1, INPUT); pinMode(PIR_2, INPUT); digitalWrite(PIR_1, LOW); digitalWrite(PIR_2, LOW); Serial.begin(9600); // set master brightness control FastLED.setBrightness(BRIGHTNESS); } // List of patterns to cycle through. Each is defined as a separate function below. typedef void (*SimplePatternList[])(); SimplePatternList gPatterns = { confetti }; uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current uint8_t gHue = 0; // rotating "base color" used by many of the patterns int i = 0; bool status = false; void loop() { Serial.print(digitalRead(PIR_1) == HIGH); Serial.print(" "); Serial.println(digitalRead(PIR_2) == HIGH); if(digitalRead(PIR_1) == HIGH || digitalRead(PIR_2) == HIGH) { } if(digitalRead(PIR_1) == HIGH || digitalRead(PIR_2) == HIGH) { status = true; FastLED.setBrightness(BRIGHTNESS); digitalWrite(PIR_1,LOW); digitalWrite(PIR_2,LOW); // Call the current pattern function once, updating the 'leds' array gPatterns[gCurrentPatternNumber](); // send the 'leds' array out to the actual LED strip FastLED.show(); // insert a delay to keep the framerate modest FastLED.delay(10/FRAMES_PER_SECOND); // do some periodic updates EVERY_N_MILLISECONDS( 10 ) { gHue++; } // slowly cycle the "base color" through the rainbow } else { if(status) { for(i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB::Black; } FastLED.show(); status = false; } } } void confetti() { // random colored speckles that blink in and fade smoothly fadeToBlackBy( leds, NUM_LEDS, 50); int pos = random16(NUM_LEDS); leds[pos] += CHSV( gHue + random8(64), 200, 255); }