Advertisement
atuline

FastLED - Moving dots

Sep 1st, 2014
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1.  
  2. // Moving Dots
  3. //
  4. // By: John Burroughs
  5. // Modified by: Andrew Tuline
  6. //
  7. // Date: Sept, 2014
  8. //
  9. // This is a simple FastLED (2.1 and greater) display sequence using some FastLED functions.
  10. //
  11. // FastLED 2.1 is available at https://github.com/FastLED/FastLED/tree/FastLED2.1
  12. //
  13. // Note: If you receive compile errors (as I have in the Stino add-on for Sublime Text), set the compiler to 'Full Compilation'.
  14. //
  15.  
  16.  
  17. #include <FastLED.h>                                           // FastLED library
  18.  
  19. #define LED_DT 13                                              // Data pin
  20. #define NUM_LEDS 24                                            // Number of LED's
  21. #define COLOR_ORDER GRB                                        // Change the order as necessary
  22. #define LED_TYPE WS2811                                        // What kind of strip are you using?
  23. #define BRIGHTNESS  196                                        // How bright do we want to go
  24.  
  25. struct CRGB leds[NUM_LEDS];                                    // Initializxe our array
  26.  
  27.  
  28. // Initialize global variables for sequences
  29. int thisdelay = 4;                                                 // A delay value for the sequence(s)
  30. uint8_t count;                                                     // Count up to 255 and then reverts to 0
  31.  
  32. long currentMillis = 0;
  33. long previousMillis = 0;
  34.  
  35.  
  36. void setup() {
  37.   Serial.begin(9600);
  38.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  39.   FastLED.setBrightness(BRIGHTNESS);
  40. } // setup()
  41.  
  42.  
  43. void loop () {
  44.   dots();
  45. } // loop()
  46.  
  47.  
  48. void dots() {
  49. currentMillis = millis();
  50.   if(currentMillis - previousMillis > thisdelay) {
  51.  
  52.   uint8_t middle = 0;
  53.   uint8_t side = 0;
  54.   uint8_t other = 0;
  55.   count++;                                                     // overflowing a byte => 0
  56.  
  57.   byte x = quadwave8(count);
  58.  
  59.   other = map(x, 0, 255, NUM_LEDS/4, NUM_LEDS/4*3);            // 1/4 to 3/4 of strip
  60.   side = map(x, 0, 255, 0, NUM_LEDS-1);                        // full length of strip
  61.   middle = map(x, 0, 255, NUM_LEDS/3, NUM_LEDS/3*2);           // 1/3 to 2/3 of strip
  62.  
  63.  
  64.   leds[middle] = CRGB::Purple;
  65.   leds[side] = CRGB::Blue;
  66.   leds[other] = CRGB::Aqua;
  67.  
  68.   LEDS.show();
  69.  
  70.   for ( byte i = 0; i < NUM_LEDS; i++) {
  71.     leds[i].fadeToBlackBy(32);
  72. //    leds[i].nscale8(180);
  73.   }
  74.  
  75.   LEDS.show();
  76.   previousMillis = currentMillis;
  77.   }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement