Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //breath effect implementation
- //fastled ledstrip demo
- //Yaroslaw Turbin 25.08.2020
- //https://vk.com/ldirko
- //https://www.reddit.com/user/ldirko/
- #include "FastLED.h"
- // LEDs pin
- #define DATA_PIN 3
- // LED brightness
- #define BRIGHTNESS 255
- #define NUM_LEDS 60 // number of leds in strip
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- #define SMOOTHERSTEP(x) ((x) * (x) * (x) * ((x) * ((x) * 6 - 15) + 10)) // https://en.wikipedia.org/wiki/Smoothstep#Variations
- #define min_bright 40
- #define max_bright BRIGHTNESS
- float a = 0;
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- }
- float inverse_smoothstep(float x) { // https://en.wikipedia.org/wiki/Smoothstep#Variations
- return 0.5 - sin(asin(1 - 2 * x) / 3);}
- void loop() {
- float b = (sin (a)+1)/2; //get 0-1 cycle value
- float v = SMOOTHERSTEP(b); //SMOOTHERSTEP it
- //float v = inverse_smoothstep(b); //uncomment this for inverse smoothstep. very nice looking breath!
- int color = (50 * v) + (255 * (1 - v)); //interpolate beetween min and max value
- fill_solid(leds, NUM_LEDS, CHSV(0, 255, color));
- a+=0.03;
- FastLED.delay(15);
- } //loop
Add Comment
Please, Sign In to add comment