wilmouths / RGBLed

An Arduino library to control RGB led
GNU General Public License v3.0
42 stars 20 forks source link

Request for Max/Min Brightness for fadeIn/fadeOut #9

Closed smizles closed 2 years ago

smizles commented 3 years ago

I'm not sure how to modify this to set a maximum brightness for the fadeIn() function. I'm trying to use an LED strip for a night light, and fade to FULL brightness will not be acceptable. Also, in thinking about it, if I wanted to create a "breathing" effect in another project, I would probably only want to fade to a certain minimum brightness before starting to fade back in.

If you have the time, please implement this!

smizles commented 3 years ago

UPDATE: It looks like this functionality already exists in the RGBLed.cpp definition, but it needs to be added to the documentation? Specifically:

void RGBLed::fade(int red, int green, int blue, int steps, int duration, int value, bool wait) {
    float brightness = float(value) / 255.f;

    color(red * brightness, green * brightness, blue * brightness);

    if (wait) { delay((unsigned long) (duration / steps)); }
}

I'm going to try experimenting with it now. Maybe I'll be able to submit a pull request for this myself (I'm new to GitHub, so it would be my first PR).

wilmouths commented 3 years ago

Hello, I could possibly add a "breathing" function, I don't have the time right now, as soon as I manage to free up some time I'll look into the subject. If you have a solution, you can make a PR that I will test and merge if the solution suits me.

hpreston commented 2 years ago

I just submitted PR #11 that I think would address this request.

A new "stored" brightness level is added to the LED object. So calls to Fade in or out will fade from the current brightness level or up to the configured brightness.

wilmouths commented 2 years ago

PR https://github.com/wilmouths/RGBLed/pull/11 was merged, can I close ?

spuder commented 2 years ago

Thank you. I can confirm that version 1.0.10 of RGBLed does now allow a Max Brightness

# Set max brightness to 10%
# Gradually fade from 0% to maxbrightness over 1 second with 5 steps)
# Gradually fade from maxbrightness to 0% over 1 second with 5 steps)
rgbLed.brightness(RGBLed::RED, 10);
rgbLed.fadeIn(RGBLed::RED, 5, 1000);
rgbLed.fadeOut(RGBLed::RED, 5, 1000);

Though my testing, I've been unable to find a Min Brightness equivalent.

I want to have a breathing effect between 50% and 100% brightness.