Advertisement
Guest User

Untitled

a guest
Aug 12th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define NUM_LEDS  56
  4. #define LED_PIN   2
  5.  
  6. CRGBArray<NUM_LEDS> leds;
  7.  
  8. uint8_t patternCounter = 0;
  9.  
  10. //wipe pattern colors
  11. CRGB bgColor = CRGB(0,0,0);
  12. CRGB wipeColor = CRGB(0,0,255);
  13. CRGB fgColor = wipeColor;
  14. uint16_t wipeStepTime = 20;
  15. uint8_t wipeStart;     // wipe start pixel position
  16. uint8_t wipeEnd;       // wipe end pixel position
  17.  
  18. void setup() {
  19.   FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  20.   FastLED.setBrightness(150);
  21.   Serial.begin(57600);
  22. }
  23.  
  24. void loop() {
  25.  
  26.   switch (patternCounter) {
  27.     case 0:
  28.       allBlank();
  29.       break;
  30.     case 1:
  31.       sakura( leds);
  32.       break;
  33.     case 2:
  34.       fillBlue();
  35.       break;
  36.   }
  37.  
  38.   EVERY_N_SECONDS(5) {
  39.     nextPattern();
  40.   }
  41.  
  42.   FastLED.show();
  43. }
  44.  
  45. void nextPattern() {
  46.   patternCounter = (patternCounter + 1) % 3;  // Change the number after the % to the number of patterns you have
  47. }
  48.  
  49. void fillBlue() {
  50.  
  51.   EVERY_N_MILLISECONDS(wipeStepTime) {
  52.     fill_solid(leds, NUM_LEDS, bgColor);
  53.  
  54.     if (wipeEnd < NUM_LEDS-1) {
  55.       wipeEnd++;
  56.       fgColor = wipeColor;
  57.     }
  58.     else if (wipeStart < NUM_LEDS-1) {
  59.       wipeStart++;
  60.     }
  61.     else if (fgColor == bgColor) {
  62.       wipeStart = 0;  // reset wipe
  63.       wipeEnd = 0;
  64.       fgColor = wipeColor;
  65.     }
  66.     else if (wipeStart == NUM_LEDS-1 && wipeEnd == NUM_LEDS-1) {
  67.       fgColor = bgColor;
  68.     }
  69.    
  70.     fill_gradient_RGB (leds, wipeStart, fgColor, wipeEnd, fgColor );
  71.  
  72.   FastLED.show();
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement