Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define LED_TYPE NEOPIXEL
- #define NUM_STRIPS 5
- #define NUM_LEDS 7
- #define BRIGHTNESS 20
- #define FRAMES_PER_SECOND 120
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- int PIR1 = A0; // Set the input pins for PIR sensors
- int pirState = LOW; // Start assuming no motion detected
- int val1 = 0; // Variable for reading the pin status
- CRGB leds1[NUM_LEDS];
- CRGB leds2[NUM_LEDS];
- CRGB *strips[] = {leds1, leds2};
- uint8_t chanceOfGlitter = 80;
- int stripIndex = 0;
- //---------------------------------------------------------------
- void setup() {
- Serial.begin(9600); // Allows serial monitor output (check baud rate)
- delay(3000);
- FastLED.addLeds<LED_TYPE, 2>(leds1, NUM_LEDS); // Assign data pins
- FastLED.addLeds<LED_TYPE, 3>(leds2, NUM_LEDS);
- FastLED.setBrightness( BRIGHTNESS );
- pinMode(PIR1, INPUT); // declare sensor as input
- }
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = { confetti, rainbowWithGlitter, rainbow, sinelon2, bpm, juggle };
- uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
- uint8_t gHue = 0; // rotating "base color" used by many of the patterns
- //---------------------------------------------------------------
- void loop() {
- val1 = digitalRead(PIR1); // read input value
- EVERY_N_SECONDS( random8(60) ) {val1 = HIGH;} // Randomly activate this set of lights
- if (val1 == HIGH) { // check if the input is HIGH
- stripIndex = 0;
- gPatterns[gCurrentPatternNumber]();
- stripIndex = 1;
- gPatterns[gCurrentPatternNumber]();
- FastLED.show();
- }
- else {
- for( int i = 0; i < NUM_LEDS; i++) {
- leds1[i] %= 64;
- FastLED.show();
- leds1[i].maximizeBrightness();
- }
- }
- // insert a delay to keep the framerate modest
- FastLED.delay(1000/FRAMES_PER_SECOND);
- // do some periodic updates
- EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
- EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
- //Periodically activate all lights
- EVERY_N_SECONDS( random8(60) ) {val1 = HIGH;}
- Serial.println(val1);
- }//end main loop
- void nextPattern()
- {
- // add one to the current pattern number, and wrap around at the end
- gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
- }
- void rainbow()
- {
- // FastLED's built-in rainbow generator
- fill_rainbow( strips[stripIndex], NUM_LEDS, gHue, 7);
- }
- void rainbowWithGlitter()
- {
- // built-in FastLED rainbow, plus some random sparkly glitter
- rainbow();
- addGlitter(80);
- }
- void addGlitter( fract8 chanceOfGlitter)
- {
- if( random8() < chanceOfGlitter) {
- strips[stripIndex][ random16(NUM_LEDS) ] += CRGB::White;
- }
- }
- void confetti()
- {
- // random colored speckles that blink in and fade smoothly
- fadeToBlackBy( strips[stripIndex], NUM_LEDS, 10);
- int pos = random16(NUM_LEDS);
- strips[stripIndex][pos] += CHSV( gHue + random8(64), 200, 255);
- }
- void bpm()
- {
- // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = PartyColors_p;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- strips[stripIndex][i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- // Updated sinelon (no visual gaps)
- void sinelon2()
- {
- // a colored dot sweeping
- // back and forth, with
- // fading trails
- fadeToBlackBy( strips[stripIndex], NUM_LEDS, 20);
- int pos = beatsin16(13,0,NUM_LEDS);
- static int prevpos = 0;
- if( pos < prevpos ) {
- fill_solid( strips[stripIndex]+pos, (prevpos-pos)+1, CHSV(gHue,220,255));
- } else {
- fill_solid( strips[stripIndex]+prevpos, (pos-prevpos)+1, CHSV( gHue,220,255));
- }
- prevpos = pos;
- }
- void juggle() {
- // eight colored dots, weaving in and out of sync with each other
- uint8_t x = stripIndex;
- fadeToBlackBy( strips[x], NUM_LEDS, 20);
- byte dothue = 0;
- for( int i = 0; i < 8; i++) {
- strips[x][beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
- dothue += 32;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment