Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 3
- #define NUM_LEDS 20
- #define BRIGHTNESS 64
- #define LED_TYPE WS2812
- #define COLOR_ORDER BRG
- CRGB leds[NUM_LEDS];
- DEFINE_GRADIENT_PALETTE( greens_gp ) {
- 0, 0,255,0 ,
- 150, 255,0,100,
- 255, 0,255,0 };
- DEFINE_GRADIENT_PALETTE( reds_gp ) {
- 0, 255,0,60,
- 150, 0,255,50,
- 255, 255,0,60};
- DEFINE_GRADIENT_PALETTE( blues_gp ) {
- 0, 188,0,255,
- 150, 50,0,255,
- 255, 255,0,0};
- CRGBPalette16 greens = greens_gp;
- CRGBPalette16 reds = reds_gp;
- CRGBPalette16 blues = blues_gp;
- CRGBPalette16 currentPalette = reds_gp;
- CRGBPalette16 targetPalette = blues_gp;
- void setup() {
- Serial.begin(9600);
- delay( 1000 ); // power-up safety delay
- fill_solid(leds, NUM_LEDS, CRGB(0,0,0));
- FastLED.show();
- delay(1000);
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- }
- void fillLeds( uint8_t colorIndex, uint8_t changeamount) {
- uint8_t brightness = 255;
- for( int i = 0; i < NUM_LEDS; i++) {
- leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, LINEARBLEND);
- colorIndex = colorIndex+changeamount;
- if(colorIndex > 255) {colorIndex = 255;}
- }
- }
- void ChangePalette() {
- int paletti = random8(60);
- if(paletti < 20) { currentPalette = reds; }
- if(paletti > 20 && paletti < 40) { currentPalette = greens; }
- if(paletti > 40) { currentPalette = blues; }
- }
- void loop() {
- EVERY_N_SECONDS(30) { ChangePalette(); }
- static uint8_t index = 0;
- uint8_t changeamount = 255/NUM_LEDS;
- fillLeds(index, changeamount);
- FastLED.show();
- uint8_t maxChanges = 12;
- nblendPaletteTowardPalette( currentPalette, targetPalette, maxChanges);
- delay(2);
- }
Advertisement
Add Comment
Please, Sign In to add comment