Guest User

Untitled

a guest
Oct 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. FASTLED_USING_NAMESPACE
  4.  
  5.  
  6. //credit to -Mark Kriegsman
  7. //credit to -Marc Miller
  8.  
  9.  
  10. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  11. #warning "Requires FastLED 3.1 or later; check github for latest code."
  12. #endif
  13.  
  14. #define DATA_PIN 7
  15. #define CLK_PIN 11
  16. #define SPISpeed 16
  17. #define LED_TYPE APA102
  18. #define COLOR_ORDER RGB
  19. #define NUM_LEDS 144
  20.  
  21.  
  22. #define BRIGHTNESS 96
  23. #define FRAMES_PER_SECOND 120
  24.  
  25. uint8_t pps = 24; // number of Pixels Per Segment
  26. int pos;
  27. uint8_t NumStrips=2;
  28. uint8_t delta =1;
  29.  
  30. CRGBArray<NUM_LEDS> leds;
  31.  
  32. // Name segments (based on layout in link above) and define pixel ranges.
  33. CRGBSet Strip_1( leds(pps*0, pps-1+(pps*0) ));
  34. //CRGBSet Strip_2( leds(pps*1, pps-1+(pps*1) )); //if i uncomment and comment the next line (strip_1 and strip_2)pixels are moving in one direction
  35. CRGBSet Strip_2( leds((pps-1)+(pps*1), pps*1 )); //if i uncomment and comment the previuos line strip_2 pixels are not moving in opposite direction
  36. CRGBSet Strip_3( leds(pps*2, pps-1+(pps*2) ));
  37. CRGBSet Strip_4( leds(pps*3, pps-1+(pps*3) ));
  38. CRGBSet Strip_5( leds(pps*4, pps-1+(pps*4) ));
  39. CRGBSet Strip_6( leds(pps*5, pps-1+(pps*5) ));
  40.  
  41.  
  42. struct CRGB * LEDArray[] ={Strip_1, Strip_2, Strip_3, Strip_4, Strip_5, Strip_6};
  43.  
  44.  
  45. void setup() {
  46. delay(3000); // 3 second delay for recovery
  47.  
  48. // tell FastLED about the LED strip configuration
  49. // FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  50. FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER,DATA_RATE_MHZ(SPISpeed)>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  51.  
  52. // set master brightness control
  53. FastLED.setBrightness(BRIGHTNESS);
  54. }
  55.  
  56.  
  57. // List of patterns to cycle through. Each is defined as a separate function below.
  58. typedef void (*SimplePatternList[])();
  59. SimplePatternList gPatterns = { white_dot, Blue_dot };
  60.  
  61. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  62.  
  63.  
  64. void loop()
  65. {
  66. // Call the current pattern function once, updating the 'leds' array
  67. gPatterns[gCurrentPatternNumber]();
  68.  
  69. EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
  70. }
  71.  
  72. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  73.  
  74. void nextPattern()
  75. {
  76. // add one to the current pattern number, and wrap around at the end
  77. gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  78. }
  79.  
  80. void white_dot()
  81. {
  82.  
  83. EVERY_N_MILLISECONDS( 20 ){
  84.  
  85. for (int y=0; y < NumStrips; y++ ) {
  86. LEDArray[y][pos] = CRGB::White;
  87. }
  88.  
  89. FastLED.show();
  90.  
  91. for (int y=0; y < NumStrips; y++ ) {
  92. LEDArray[y][pos] = CRGB::Black;
  93. }
  94.  
  95. pos = (pos + delta + pps) % pps ;
  96. }
  97. }
  98.  
  99. void Blue_dot()
  100. {
  101.  
  102. EVERY_N_MILLISECONDS( 20 ) {
  103.  
  104.  
  105. for (int y=0; y < NumStrips; y++ ) {
  106. LEDArray[y][pos] = CRGB::Blue;
  107. }
  108.  
  109. FastLED.show();
  110.  
  111. for (int y=0; y < NumStrips; y++ ) {
  112. LEDArray[y][pos] = CRGB::Black;
  113. }
  114.  
  115. pos = (pos + delta + pps) % pps ;
  116. }
  117. }
Add Comment
Please, Sign In to add comment