ldirko

Breathing

Aug 25th, 2020 (edited)
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //breath effect implementation
  2. //fastled ledstrip demo
  3. //Yaroslaw Turbin 25.08.2020
  4. //https://vk.com/ldirko
  5. //https://www.reddit.com/user/ldirko/
  6.  
  7. #include "FastLED.h"
  8. // LEDs pin
  9. #define DATA_PIN 3
  10. // LED brightness
  11. #define BRIGHTNESS 255
  12. #define NUM_LEDS 60  // number of leds in strip
  13. // Define the array of leds
  14. CRGB leds[NUM_LEDS];
  15.  
  16. #define SMOOTHERSTEP(x) ((x) * (x) * (x) * ((x) * ((x) * 6 - 15) + 10))  // https://en.wikipedia.org/wiki/Smoothstep#Variations
  17. #define min_bright 40
  18. #define max_bright BRIGHTNESS
  19. float a = 0;
  20.  
  21. void setup() {
  22.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  23.   FastLED.setBrightness(BRIGHTNESS);
  24. }
  25.  
  26. float inverse_smoothstep(float x) {               // https://en.wikipedia.org/wiki/Smoothstep#Variations
  27. return 0.5 - sin(asin(1 - 2 * x) / 3);}
  28.  
  29. void loop() {
  30. float b = (sin (a)+1)/2;   //get 0-1 cycle value
  31. float v = SMOOTHERSTEP(b);  //SMOOTHERSTEP it
  32. //float v = inverse_smoothstep(b);  //uncomment this for inverse smoothstep. very nice looking breath!
  33. int color = (50 * v) + (255 * (1 - v)); //interpolate beetween min and max value
  34. fill_solid(leds, NUM_LEDS, CHSV(0, 255, color));
  35. a+=0.03;
  36. FastLED.delay(15);
  37. } //loop
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
Add Comment
Please, Sign In to add comment