ldirko

simple breath effect

Aug 10th, 2020 (edited)
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "FastLED.h"
  2.  
  3. // LEDs pin
  4. #define DATA_PIN 3
  5.  
  6. // LED brightness
  7. #define BRIGHTNESS 240
  8.  
  9. #define NUM_LEDS 30
  10.  
  11. // Define the array of leds
  12. CRGB leds[NUM_LEDS];
  13.  
  14. void setup() {
  15.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  16.   FastLED.setBrightness(BRIGHTNESS);
  17. }
  18.  
  19. void loop() {
  20. #define MIN_BRIGHTNESS 50
  21. #define MAX_BRIGHTNESS BRIGHTNESS
  22. #define HUE_COLOR 0    // red color
  23. #define SPEED_FADE 15    //speed of effect
  24.  
  25. int  a = millis();
  26.  byte b = triwave8 (a/SPEED_FADE);
  27.  
  28.        byte breath = ease8InOutCubic (b);
  29.         breath = map (breath,0,255, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
  30.         fill_solid(leds, NUM_LEDS, CHSV(HUE_COLOR, 255, breath));
  31.       //fill_gradient(leds,NUM_LEDS,CHSV(0,255,MIN_BRIGHTNESS),CHSV(0,255,breath), CHSV(0,255,breath), CHSV(0,255,MIN_BRIGHTNESS),LONGEST_HUES);  // uncomment this to smooth gradient looking effect
  32.  
  33.         adjust_gamma();  
  34.  
  35.   FastLED.delay(50);
  36.  
  37. }
  38.  
  39.  
  40.  
  41. void adjust_gamma()   // https://www.reddit.com/r/FastLED/comments/b2mlvf/gamma_correction/eity0u1?utm_source=share&utm_medium=web2x
  42.                      // Marc Millers simple gamma correction
  43.  
  44.  {
  45.   for (uint16_t i = 0; i < NUM_LEDS; i++)
  46.   {
  47.     leds[i].r = dim8_video(leds[i].r);
  48.     leds[i].g = dim8_video(leds[i].g);
  49.     leds[i].b = dim8_video(leds[i].b);
  50.   }
  51. }
Add Comment
Please, Sign In to add comment