Advertisement
Double_G

TEST

Feb 8th, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <FastLED.h>
  3.  
  4. #define LED_PIN     13
  5. #define NUM_LEDS   42
  6. #define BRIGHTNESS  64
  7. #define LED_TYPE    WS2812
  8. #define COLOR_ORDER GRB
  9. CRGB leds[NUM_LEDS];
  10.  
  11. #define UPDATES_PER_SECOND 5000
  12.  
  13.  
  14. CRGBPalette16 currentPalette;
  15. TBlendType    currentBlending;
  16.  
  17. extern CRGBPalette16 myRedWhiteBluePalette;
  18. extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
  19.  
  20.  
  21. void setup() {
  22.     delay( 3000 ); // power-up safety delay
  23.     FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  24.     FastLED.setBrightness(  BRIGHTNESS );
  25.     FastLED.show();
  26.     currentPalette = RainbowColors_p;
  27.     currentBlending = LINEARBLEND;
  28.     //Serial.begin(115200);
  29. }
  30.  
  31.  
  32. void FillLEDsFromPaletteColors( uint8_t colorIndex)
  33. {
  34.     uint8_t brightness = 255;
  35.    
  36.     for( int i = 0; i < NUM_LEDS; i++) {
  37.         leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
  38.         colorIndex += 3;
  39.     }
  40. }
  41.  
  42.  
  43. void SetupBlackAndWhiteStripedPalette()
  44. {
  45.     // 'black out' all 16 palette entries...
  46.     fill_solid( currentPalette, 32, CRGB::Black);
  47.     // and set every fourth one to white.
  48.     currentPalette[0] = CRGB::White;
  49.     currentPalette[8] = CRGB::White;
  50.     currentPalette[16] = CRGB::White;
  51.     currentPalette[24] = CRGB::White;
  52.    
  53. }
  54.  
  55.  
  56. void ChangePalettePeriodically()
  57. {
  58.     uint8_t secondHand = (millis() / 1000) % 60;
  59.     static uint8_t lastSecond = 99;
  60.    
  61.     if( lastSecond != secondHand) {
  62.         lastSecond = secondHand;
  63.         if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }
  64.         if( secondHand == 20)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }
  65.         if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
  66.     }
  67. }
  68.  
  69.  
  70. void loop()
  71. {
  72.     //Serial.print("1");
  73.     ChangePalettePeriodically();
  74.    
  75.     static uint8_t startIndex = 0;
  76.     startIndex = startIndex - 1; /* motion speed */
  77.    
  78.     FillLEDsFromPaletteColors( startIndex);
  79.    
  80.     FastLED.show();
  81.     FastLED.delay(1500 / UPDATES_PER_SECOND);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement