Guest User

Untitled

a guest
Mar 4th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN 3
  4. #define NUM_LEDS 20
  5. #define BRIGHTNESS 64
  6. #define LED_TYPE WS2812
  7. #define COLOR_ORDER BRG
  8. CRGB leds[NUM_LEDS];
  9.  
  10. DEFINE_GRADIENT_PALETTE( greens_gp ) {
  11. 0, 0,255,0 ,
  12. 150, 255,0,100,
  13. 255, 0,255,0 };
  14.  
  15.  
  16. DEFINE_GRADIENT_PALETTE( reds_gp ) {
  17. 0, 255,0,60,
  18. 150, 0,255,50,
  19. 255, 255,0,60};
  20.  
  21. DEFINE_GRADIENT_PALETTE( blues_gp ) {
  22. 0, 188,0,255,
  23. 150, 50,0,255,
  24. 255, 255,0,0};
  25.  
  26.  
  27. CRGBPalette16 greens = greens_gp;
  28. CRGBPalette16 reds = reds_gp;
  29. CRGBPalette16 blues = blues_gp;
  30. CRGBPalette16 currentPalette = reds_gp;
  31. CRGBPalette16 targetPalette = blues_gp;
  32.  
  33. void setup() {
  34. Serial.begin(9600);
  35. delay( 1000 ); // power-up safety delay
  36. fill_solid(leds, NUM_LEDS, CRGB(0,0,0));
  37. FastLED.show();
  38. delay(1000);
  39. FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  40. FastLED.setBrightness( BRIGHTNESS );
  41.  
  42. }
  43.  
  44. void fillLeds( uint8_t colorIndex, uint8_t changeamount) {
  45.  
  46. uint8_t brightness = 255;
  47.  
  48. for( int i = 0; i < NUM_LEDS; i++) {
  49. leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, LINEARBLEND);
  50. colorIndex = colorIndex+changeamount;
  51. if(colorIndex > 255) {colorIndex = 255;}
  52. }
  53.  
  54. }
  55.  
  56. void ChangePalette() {
  57.  
  58. int paletti = random8(60);
  59.  
  60. if(paletti < 20) { currentPalette = reds; }
  61. if(paletti > 20 && paletti < 40) { currentPalette = greens; }
  62. if(paletti > 40) { currentPalette = blues; }
  63.  
  64.  
  65. }
  66.  
  67.  
  68.  
  69. void loop() {
  70. EVERY_N_SECONDS(30) { ChangePalette(); }
  71. static uint8_t index = 0;
  72. uint8_t changeamount = 255/NUM_LEDS;
  73. fillLeds(index, changeamount);
  74. FastLED.show();
  75. uint8_t maxChanges = 12;
  76. nblendPaletteTowardPalette( currentPalette, targetPalette, maxChanges);
  77. delay(2);
  78.  
  79.  
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment