Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 3
- #define NUM_LEDS 9
- #define BRIGHTNESS 64
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB
- CRGB leds[NUM_LEDS];
- #define UPDATES_PER_SECOND 15
- CRGBPalette16 currentPalette;
- TBlendType currentBlending;
- extern CRGBPalette16 myGreenBluePalette;
- extern const TProgmemPalette16 myGreenBluePalette_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 );
- currentPalette = ForestColors_p;
- currentBlending = LINEARBLEND;
- }
- void loop()
- {
- ChangePalettePeriodically();
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* motion speed */
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(1000 / UPDATES_PER_SECOND);
- }
- 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;
- }
- }
- // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
- // OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
- void ChangePalettePeriodically()
- {
- uint8_t secondHand = (millis() / 1000) % 60;
- static uint8_t lastSecond = 99;
- if( lastSecond != secondHand) {
- lastSecond = secondHand;
- if( secondHand == 0) { currentPalette = myGreenBluePalette_p; currentBlending = NOBLEND; }
- if( secondHand == 55) { currentPalette = myGreenBluePalette_p; currentBlending = LINEARBLEND; }
- }
- }
- // This example shows how to set up a static color palette
- // which is stored in PROGMEM (flash), which is almost always more
- // plentiful than RAM. A static PROGMEM palette like this
- // takes up 64 bytes of flash.
- const TProgmemPalette16 myGreenBluePalette_p PROGMEM =
- {
- CRGB::LightCyan,
- CRGB::LightGreen,
- CRGB::Blue,
- CRGB::LightSkyBlue,
- CRGB::Lime,
- CRGB::LimeGreen,
- CRGB::MediumSeaGreen,
- CRGB::MediumTurquoise,
- CRGB::Olive,
- CRGB::PaleGoldenrod,
- CRGB::SpringGreen,
- CRGB::YellowGreen,
- CRGB::Honeydew,
- CRGB::DarkOliveGreen,
- CRGB::Chocolate,
- CRGB::BurlyWood
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement