Guest User

FastLED reverse array

a guest
Aug 9th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include "FastLED.h"
  2. FASTLED_USING_NAMESPACE
  3.  
  4. // DEFINITIONS
  5. #define LED_TYPE_4W WS2801
  6. #define CLOCK_PIN 2
  7. #define LED_STRIP_1_PIN 14
  8. #define LED_STRIP_1_NUM 37
  9. #define COLOR_ORDER BGR
  10. #define NUM_LEDS LED_STRIP_1_NUM // +other substrips which I removed from this example
  11.  
  12. // Define the start (STRIP_x_L) and end (STRIP_x_H) index of each LED substrip
  13. #define STRIP_1_L 0
  14. #define STRIP_1_H (LED_STRIP_1_NUM - 1)
  15.  
  16. // Generate array of LEDs containing the LEDs of all strips
  17. CRGB leds[NUM_LEDS];
  18.  
  19. // Initialise all LED substrips.
  20. FastLED.addLeds<LED_TYPE_4W, LED_STRIP_1_PIN, CLOCK_PIN, COLOR_ORDER>(leds, STRIP_1_L, LED_STRIP_1_NUM);
  21.  
  22. // Reverse some of the substrips
  23. int counter, saver;
  24. for (counter = STRIP_1_L; counter < (STRIP_1_L + LED_STRIP_1_NUM / 2); counter++) {
  25.   saver = leds[counter];
  26.   leds[counter] = leds[STRIP_1_H - counter];
  27.   leds[STRIP_1_H - counter] = saver;
  28. }
  29.  
  30.  
  31. // Now I run a dot from leds[0] to leds[end]
  32. for (int dot = 0; dot < NUM_LEDS; dot++) { // red moving dot
  33.   leds[dot] = CRGB::Red;
  34.   FastLED.show();
  35.   leds[dot] = CRGB::Black;
  36.   FastLED.delay(30);  // wait for 30 ms
  37. }
  38. FastLED.show(); // all LEDs black again
  39.  
  40. // This is the problem, even though I reversed the array. The red dot still start on the side where the LED strip is connected with the // wires. It should start on the opposite side. Please help to fix this!
Add Comment
Please, Sign In to add comment