Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- // Number of RGB LEDs in the strand
- #define NUM_LEDS 20
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- // Arduino pin used for Data
- //#define PIN 13
- #define PIN 2
- #define FRAMES_PER_SECOND 120
- byte anim_count =0;
- void setup()
- {
- FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(40);
- boot_animation();
- }
- // List of patterns to cycle through. Each is defined as a separate function below.
- typedef void (*SimplePatternList[])();
- //SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, sinelon, juggle };
- SimplePatternList gPatterns = { rainbow, sinelon, sinelon1way};
- 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()
- {
- // 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(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
- }
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- 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( leds, 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) {
- leds[ random16(NUM_LEDS) ] += CRGB::White;
- }
- }
- */
- void sinelon()
- {
- // a colored dot sweeping back and forth, with fading trails
- fadeToBlackBy( leds, NUM_LEDS, 20);
- uint8_t pos = beatsin16(20,0,NUM_LEDS/2 );
- leds[pos] += CHSV( gHue, 255, 192);
- leds[pos + NUM_LEDS/2] += CHSV( gHue, 255, 192);
- }
- void sinelon1way(){
- // a colored dot sweeping forth, with fading trails
- fadeToBlackBy( leds, NUM_LEDS, 20);
- uint8_t pos = ((millis() / 70) % NUM_LEDS/2 );
- leds[pos] += CHSV( gHue, 255, 192);
- leds[pos + NUM_LEDS/2] += CHSV( gHue, 255, 192);
- }
- void boot_animation(){
- //red booting blinking
- for(int l = 0; l < 20 ; l++) {
- if(l % 2){
- for(byte i = 0 ; i < NUM_LEDS; i++){
- leds[i] = CRGB(255,0,0);
- }
- FastLED.show();
- delay(250);
- }
- else{
- FastLED.clear();
- FastLED.show();
- delay(250);
- }
- }
- while(1){
- uint8_t pos = ((millis() / 70) % NUM_LEDS/2 );
- if (anim_count < 1){
- leds[pos] += CRGB(255,0,0);
- leds[pos + NUM_LEDS/2] += CRGB(255,0,0);
- }
- else{
- leds[pos] += CRGB(0,255,0);
- leds[pos + NUM_LEDS/2] += CRGB(0,255,0);
- }
- if(anim_count == 3)
- break;
- fadeToBlackBy( leds, NUM_LEDS, 15);
- FastLED.show();
- // insert a delay to keep the framerate modest
- FastLED.delay(1000/FRAMES_PER_SECOND);
- EVERY_N_SECONDS( 10 ) { anim_count++; }
- }
- for(byte i = 0 ; i < NUM_LEDS; i++){
- leds[i] = CRGB(0,255,0);
- }
- FastLED.show();
- delay(2000);
- FastLED.clear();
- FastLED.show();
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment