Advertisement
atuline

Moving dots in time.

Aug 19th, 2015
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. /*
  2.  
  3. The goal of this test sketch is to run multiple strips where each dot could be turned on one after the other but with different times on/off between each pixel on each strip.
  4.  
  5. By: Andrew Tuline
  6. Date: August, 2015
  7.  
  8. Assumptions:
  9.  
  10. - Each element in the array is greater than the one previous.
  11. - The last element in the array is the end of the line.
  12.  
  13. Note that there are NO nasty 'for' or blocking delays.
  14.  
  15. */
  16.  
  17.  
  18. #include <FastLED.h>
  19.  
  20. #define NUM_LEDS1 10
  21. #define NUM_LEDS2 6
  22.  
  23. // Define pin (each strip be connected on)
  24. #define DATA_PIN1 5
  25. #define DATA_PIN2 6
  26.  
  27. uint8_t fadeval = 128;
  28.  
  29. // Declare the strips
  30. CRGB leds1[NUM_LEDS1];
  31. CRGB leds2[NUM_LEDS2];
  32.  
  33. // Each element in the array is a time in ms %( the last element) to turn on.
  34. // Example : strip1= pixel_0:100ms, pixel_1:200ms, pixel_2:300ms, pixel_3:400ms, pixel_4:500ms, pixel_5:600ms, pixel_6:700ms, pixel_7:800ms, pixel_8:900ms, pixel_9:1000ms
  35. int dot_delay1[] = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
  36. int dot_delay2[] = {100, 200, 300, 400, 500, 600};
  37.  
  38.  
  39. void setup() {
  40.   Serial.begin(57600);
  41.   FastLED.addLeds<NEOPIXEL, DATA_PIN1>(leds1, NUM_LEDS1);
  42.   FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);
  43. } // setup()
  44.  
  45.  
  46.  
  47. void loop() {
  48.  
  49.   static int counter1 = 0;
  50.   static int counter2 = 0;
  51.  
  52.   if (dot_delay1[counter1] - millis()%1000 < 5) {leds1[counter1] = CRGB::Blue; counter1 = (counter1+1) % (NUM_LEDS1);}
  53.   if (dot_delay2[counter2] - millis()%600 < 5) {leds2[counter2] = CRGB::Blue; counter2 = (counter2+1) % (NUM_LEDS2); }
  54.  
  55.   FastLED.show();
  56.  
  57.   fadeToBlackBy(leds1, NUM_LEDS1, fadeval);                     // 8 bit, 1 = slow, 255 = fast
  58.   fadeToBlackBy(leds2, NUM_LEDS2, fadeval);                     // 8 bit, 1 = slow, 255 = fast
  59. } // loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement