xw4

Untitled

xw4
Aug 19th, 2015
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 KB | None | 0 0
  1. // The goal of the sketch is to run multiple strip where each dot could be controled on/off one after the others but with different times on/off between each pixel on each strip
  2. // All be indepandant and separate and automated and structured allready like FastLED library recommandation.
  3.  
  4. // Library include
  5.  
  6. #include <FastLED.h>
  7.  
  8.  
  9. #define NUM_LEDS1 10
  10. #define NUM_LEDS2 6
  11.  
  12. // Define pin (each strip be connected on)
  13. #define DATA_PIN1 5
  14. #define DATA_PIN2 6
  15.  
  16. // Declare some strip name and attribute (number of led per strip)
  17.  
  18. CRGB leds1[NUM_LEDS1];
  19. CRGB leds2[NUM_LEDS2];
  20.  
  21. void setup() {
  22.   FastLED.addLeds<NEOPIXEL, DATA_PIN1>(leds1, NUM_LEDS1);
  23.   FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);
  24. }
  25. // This is where i put some value for indicate ''delay'' time in millisecond for each strip
  26. // Example : dot_delay1 is for strip1 and every value is regardless about how much time each pixel/led in each strip be lighted before going to the second one
  27. // 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
  28. // note then number of value in array = NUM_LEDSX
  29. int dot_delay1[] = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
  30. int dot_delay2[] = {100, 200, 300, 400, 500, 600};
  31.  
  32.  
  33. void loop() {
  34. // This is where i tell to go one dot/pixel to another for each strip/num_led
  35.   for (int dot = 0; dot < NUM_LEDS1; dot++) {
  36.     for (int dot = 0; dot < NUM_LEDS2; dot++) {
  37. // This is where i said every dot going to be blue
  38.       leds1[dot] = CRGB::Blue;
  39.       leds2[dot] = CRGB::Blue;
  40.      
  41. // Show led statut
  42.       FastLED.show();
  43. // This is where i said every dot going to be black
  44.       leds1[dot] = CRGB::Black;
  45.       leds2[dot] = CRGB::Black;
  46.       // Store current time in previousMillis variable
  47.       unsigned long previousMillis = millis();
  48.       // Create boolean variables to monitor if the first strip and second strip have triggered yet
  49.       bool delayFlag1 = false, delayFlag2 = false;
  50.       // Loop continuously
  51.       while (1) {
  52.         // If the first delay time has passed, delayFlag1 is true
  53.         if ((unsigned long)(millis() - previousMillis) >= dot_delay1[dot]) {
  54.           delayFlag1 = true;
  55.         }
  56.         // If the second delay time has passed, delayFlag2 is true
  57.         if ((unsigned long)(millis() - previousMillis) >= dot_delay2[dot]) {
  58.           delayFlag2 = true;
  59.         }
  60.         // If both delay times have passed (both delay flags are true), exit while loop
  61.         if ((delayFlag1 && delayFlag2) == true) {
  62.           return;
  63.         }
  64.       }
  65.     }
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment