Double_G

LGT8F328P+Fastled

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