steveof2620

FastLED Rainbow Function

Dec 15th, 2019
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN     6
  4.  
  5. // Information about the LED strip itself
  6. #define NUM_LEDS    30
  7. #define CHIPSET     WS2812
  8. #define COLOR_ORDER GRB
  9. CRGB leds[NUM_LEDS];
  10.  
  11. #define BRIGHTNESS  19
  12.  
  13.  
  14. // FastLED v2.1 provides two color-management controls:
  15. //   (1) color correction settings for each LED strip, and
  16. //   (2) master control of the overall output 'color temperature'
  17. //
  18. // THIS EXAMPLE demonstrates the second, "color temperature" control.
  19. // It shows a simple rainbow animation first with one temperature profile,
  20. // and a few seconds later, with a different temperature profile.
  21. //
  22. // The first pixel of the strip will show the color temperature.
  23. //
  24. // HELPFUL HINTS for "seeing" the effect in this demo:
  25. // * Don't look directly at the LED pixels.  Shine the LEDs aganst
  26. //   a white wall, table, or piece of paper, and look at the reflected light.
  27. //
  28. // * If you watch it for a bit, and then walk away, and then come back
  29. //   to it, you'll probably be able to "see" whether it's currently using
  30. //   the 'redder' or the 'bluer' temperature profile, even not counting
  31. //   the lowest 'indicator' pixel.
  32. //
  33. //
  34. // FastLED provides these pre-conigured incandescent color profiles:
  35. //     Candle, Tungsten40W, Tungsten100W, Halogen, CarbonArc,
  36. //     HighNoonSun, DirectSunlight, OvercastSky, ClearBlueSky,
  37. // FastLED provides these pre-configured gaseous-light color profiles:
  38. //     WarmFluorescent, StandardFluorescent, CoolWhiteFluorescent,
  39. //     FullSpectrumFluorescent, GrowLightFluorescent, BlackLightFluorescent,
  40. //     MercuryVapor, SodiumVapor, MetalHalide, HighPressureSodium,
  41. // FastLED also provides an "Uncorrected temperature" profile
  42. //    UncorrectedTemperature;
  43.  
  44. #define TEMPERATURE_1 Candle
  45.  
  46. #define TEMPERATURE_2 Halogen
  47.  
  48. // How many seconds to show each temperature before switching
  49. #define DISPLAYTIME 40
  50. // How many seconds to show black between switches
  51. #define BLACKTIME   3
  52.  
  53. void loop()
  54. {
  55.   // draw a generic, no-name rainbow
  56.   static uint8_t starthue = 0;
  57.   fill_rainbow( leds + 1, NUM_LEDS - 1, --starthue, 20);
  58.  
  59.   // Choose which 'color temperature' profile to enable.
  60.   uint8_t secs = (millis() / 1000) % (DISPLAYTIME * 2);
  61.   if( secs < DISPLAYTIME) {
  62.     FastLED.setTemperature( TEMPERATURE_1 ); // first temperature
  63.     leds[0] = TEMPERATURE_1; // show indicator pixel
  64.   } else {
  65.     FastLED.setTemperature( TEMPERATURE_2 ); // second temperature
  66.     leds[0] = TEMPERATURE_2; // show indicator pixel
  67.   }
  68.  
  69.   // Black out the LEDs for a few secnds between color changes
  70.   // to let the eyes and brains adjust
  71.   //if( (secs % DISPLAYTIME) < BLACKTIME) {
  72.   //  memset8( leds, 0, NUM_LEDS * sizeof(CRGB));
  73.   //}
  74.  
  75.   FastLED.show();
  76.   FastLED.delay(8);
  77. }
  78.  
  79. void setup() {
  80.   delay( 3000 ); // power-up safety delay
  81.   // It's important to set the color correction for your LED strip here,
  82.   // so that colors can be more accurately rendered through the 'temperature' profiles
  83.   FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 );
  84.   FastLED.setBrightness( BRIGHTNESS );
  85. }
Advertisement
Add Comment
Please, Sign In to add comment