Hello! Pretty new to Arduino and the WS2812 Strips in general.

Hello! Pretty new to Arduino and the WS2812 Strips in general.
I have managed to make a set of pixels follow an object using an ultrasonic sensor and randomly generate colours every 4 seconds but now I am trying to fade or pulse the overall brightness and I have become stuck. Tried to get the Wave functions to work but to no avail. Here is the code https://gist.github.com/sw4nton/8dba6120b09c6b877d68

Hi @Peter_Swanton ​,
In the setup() function of your code, you used the line:
FastLED.setBrightness(255);
That line set the whole strip to maximum brightness. So if you want to change the brightness of the whole strip during your loop() function, you can use the same line and adjust the value between 0 and 255.

If you are looking for something more interesting (fade by percentage) then read the wiki and see the examples included with the library.

I know I just set the brightness to 255 while I was testing the rest I’m now looking to go from 100% brightness to 40% and back to 100% over about 3sec’s. Would you be able to point me in the right direction as I’m having trouble finding it

@Stuart_Taylor ^^

Do you mean like a glowing apple power switch?

exactly ya! (assuming you mean the little white led on the front of most macbooks that looks like its breathing)

Ok, to recreate that effect then. you want something like f(x) = e sin(x), so

void loop () {
breath = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.4;

FastLED.setBrightness(breath);

}

You are a god damn saint

hmm actually I cant get that to work, Apologies for me being useless

http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ tried to get this working no luck

its working just fine here with 250 leds.

see: https://gist.github.com/hsiboy/4eae11073e9d5b21eae3

video will be at https://www.youtube.com/watch?v=5O94PDd1aOM in a few minutes

perfect i have that working now! :slight_smile: just one more question any idea how to make it so they dont completely turn off just dim most of the way? youve been so helpful thank you

OK, so I’ve cheated a bit. The brightness function of FastLED expects me to feed it a value between 0 (being off) and 255 (full on). The values we’re pumping to the brightness function are going to be floating point rather than nice whole integers, but it still works because there is some magic happening (but that’s also the reason we perceive some flicker).

If you want to control the limits, there are a number of ways you could do it, but as you are a beginner, you could use the arduino map() function, that would translate the discrete floating point numbers into a range you specify.

I’ll let you have a google. Then I’ll post an example.

Btw: Your eyes will be more sensitive with certain colours.

Before you suggested it I had tried the map function, will give it another shot now! I still need to figure out how to use millis() instead of the delay function in my animation, maybe tomorrow!

OK, you may also like to try constrain(), again lots of good info a google away.

The beatsin8() function of the library will help. For example, you want to fade from 10% brightness to 100% over three seconds. You would do this:

fill_solid( leds, NUM_LEDS, CHSV(hue, sat, beatsin8(20, 25, 255));

The fill_solid will fill the leds array with the hue from the CHSV conversion of the library. The beatsin8 controls the “fade” value of the CHSV conversion and walla, you get a pulsing effect!

@Jon_Burroughs ​ the “breathing” effect isn’t sinusoidal, the troughs last longer than the peaks, beatsin8() will pulse the LEDs with a regular mark space ratio that won’t mimic the apple power button. See http://www.adafruit.com/blog/2010/08/26/reverse-engineering-the-mac-breathing-led-2/

@Peter_Swanton ​ Here’s a starting place for learning to avoid using delay().
http://arduino.cc/en/Tutorial/BlinkWithoutDelay