Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 13
- #define NUM_LEDS 42
- #define BRIGHTNESS 64
- #define LED_TYPE WS2812
- #define COLOR_ORDER GRB
- CRGB leds[NUM_LEDS];
- #define UPDATES_PER_SECOND 5000
- CRGBPalette16 currentPalette;
- TBlendType currentBlending;
- extern CRGBPalette16 myRedWhiteBluePalette;
- extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
- void setup() {
- delay( 3000 ); // power-up safety delay
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- FastLED.show();
- currentPalette = RainbowColors_p;
- currentBlending = LINEARBLEND;
- //Serial.begin(115200);
- }
- void FillLEDsFromPaletteColors( uint8_t colorIndex)
- {
- uint8_t brightness = 255;
- for( int i = 0; i < NUM_LEDS; i++) {
- leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
- colorIndex += 3;
- }
- }
- void SetupBlackAndWhiteStripedPalette()
- {
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 32, CRGB::Black);
- // and set every fourth one to white.
- currentPalette[0] = CRGB::White;
- currentPalette[8] = CRGB::White;
- currentPalette[16] = CRGB::White;
- currentPalette[24] = CRGB::White;
- }
- void ChangePalettePeriodically()
- {
- uint8_t secondHand = (millis() / 1000) % 60;
- static uint8_t lastSecond = 99;
- if( lastSecond != secondHand) {
- lastSecond = secondHand;
- if( secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; }
- if( secondHand == 20) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; }
- if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; }
- }
- }
- void loop()
- {
- //Serial.print("1");
- ChangePalettePeriodically();
- static uint8_t startIndex = 0;
- startIndex = startIndex - 1; /* motion speed */
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(1500 / UPDATES_PER_SECOND);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement