Advertisement
Guest User

Untitled

a guest
Oct 7th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN 3
  4. #define NUM_LEDS 9
  5. #define BRIGHTNESS 64
  6. #define LED_TYPE WS2811
  7. #define COLOR_ORDER GRB
  8. CRGB leds[NUM_LEDS];
  9.  
  10. #define UPDATES_PER_SECOND 15
  11.  
  12.  
  13.  
  14.  
  15.  
  16. CRGBPalette16 currentPalette;
  17. TBlendType currentBlending;
  18.  
  19. extern CRGBPalette16 myGreenBluePalette;
  20. extern const TProgmemPalette16 myGreenBluePalette_p PROGMEM;
  21.  
  22.  
  23. void setup() {
  24. delay( 3000 ); // power-up safety delay
  25. FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  26. FastLED.setBrightness( BRIGHTNESS );
  27.  
  28. currentPalette = ForestColors_p;
  29. currentBlending = LINEARBLEND;
  30. }
  31.  
  32.  
  33. void loop()
  34. {
  35. ChangePalettePeriodically();
  36.  
  37. static uint8_t startIndex = 0;
  38. startIndex = startIndex + 1; /* motion speed */
  39.  
  40. FillLEDsFromPaletteColors( startIndex);
  41.  
  42. FastLED.show();
  43. FastLED.delay(1000 / UPDATES_PER_SECOND);
  44. }
  45.  
  46. void FillLEDsFromPaletteColors( uint8_t colorIndex)
  47. {
  48. uint8_t brightness = 255;
  49.  
  50. for( int i = 0; i < NUM_LEDS; i++) {
  51. leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
  52. colorIndex += 3;
  53. }
  54. }
  55.  
  56.  
  57. // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
  58. // OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
  59.  
  60.  
  61. void ChangePalettePeriodically()
  62. {
  63. uint8_t secondHand = (millis() / 1000) % 60;
  64. static uint8_t lastSecond = 99;
  65.  
  66. if( lastSecond != secondHand) {
  67. lastSecond = secondHand;
  68.  
  69. if( secondHand == 0) { currentPalette = myGreenBluePalette_p; currentBlending = NOBLEND; }
  70. if( secondHand == 55) { currentPalette = myGreenBluePalette_p; currentBlending = LINEARBLEND; }
  71. }
  72. }
  73.  
  74.  
  75.  
  76. // This example shows how to set up a static color palette
  77. // which is stored in PROGMEM (flash), which is almost always more
  78. // plentiful than RAM. A static PROGMEM palette like this
  79. // takes up 64 bytes of flash.
  80. const TProgmemPalette16 myGreenBluePalette_p PROGMEM =
  81. {
  82. CRGB::LightCyan,
  83. CRGB::LightGreen,
  84. CRGB::Blue,
  85. CRGB::LightSkyBlue,
  86.  
  87. CRGB::Lime,
  88. CRGB::LimeGreen,
  89. CRGB::MediumSeaGreen,
  90. CRGB::MediumTurquoise,
  91.  
  92. CRGB::Olive,
  93. CRGB::PaleGoldenrod,
  94. CRGB::SpringGreen,
  95. CRGB::YellowGreen,
  96.  
  97. CRGB::Honeydew,
  98. CRGB::DarkOliveGreen,
  99. CRGB::Chocolate,
  100. CRGB::BurlyWood
  101. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement