xw4

Untitled

xw4
Aug 19th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 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.  
  12. Comment from François Eric King : each element is not always greater  than the one previous. i make like this just for more clarify understanding of the purpose of the sketch but in fact all element in each array be mixed sometime grater, sometimes not.
  13.  
  14. - The last element in the array is the end of the line.
  15.  
  16. Note that there are NO nasty 'for' or blocking delays.
  17.  
  18. */
  19.  
  20.  
  21. #include <FastLED.h>
  22.  
  23. #define NUM_LEDS1 10
  24. #define NUM_LEDS2 6
  25.  
  26. // Define pin (each strip be connected on)
  27. #define DATA_PIN1 5
  28. #define DATA_PIN2 6
  29.  
  30. uint8_t fadeval = 128;
  31.  
  32. // Declare the strips
  33. CRGB leds1[NUM_LEDS1];
  34. CRGB leds2[NUM_LEDS2];
  35.  
  36. // Each element in the array is a time in ms %( the last element) to turn on.
  37. // 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
  38. int dot_delay1[] = {100, 200, 300, 400, 500, 600, 500, 0, 24, 1347.4};
  39. int dot_delay2[] = {123, 2000, 330, 4000, 550, 6000};
  40.  
  41.  
  42. void setup() {
  43.   Serial.begin(57600);
  44.   FastLED.addLeds<NEOPIXEL, DATA_PIN1>(leds1, NUM_LEDS1);
  45.   FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);
  46. } // setup()
  47.  
  48.  
  49.  
  50. void loop() {
  51.  
  52.   static int counter1 = 0;
  53.   static int counter2 = 0;
  54.  
  55.   if (dot_delay1[counter1] - millis()%1000 < 5) {leds1[counter1] = CRGB::Blue; counter1 = (counter1+1) % (NUM_LEDS1);}
  56.   if (dot_delay2[counter2] - millis()%600 < 5) {leds2[counter2] = CRGB::Blue; counter2 = (counter2+1) % (NUM_LEDS2); }
  57.  
  58.   FastLED.show();
  59.  
  60.   fadeToBlackBy(leds1, NUM_LEDS1, fadeval);                     // 8 bit, 1 = slow, 255 = fast
  61.   fadeToBlackBy(leds2, NUM_LEDS2, fadeval);                     // 8 bit, 1 = slow, 255 = fast
  62. } // loop()
Advertisement
Add Comment
Please, Sign In to add comment