Well, That's frustrating, writing a lengthy post asking for help,

Well, That’s frustrating, writing a lengthy post asking for help, with code included and specific questions, only to have it deleted by goog because they think its spam…

I’ll try again, hoping I don’t forget anything.

In the attached code, I am using the smoothed output of an HC-SR04 ultrasonic rangefinder to drive the angle of a servomotor, and the brightness of a white LED and a UV LED. The LEDs brighten or darken depending on the range read by the rangefinder, in an inverse relationship. The closer the object, the darker the white light and the brighter the UV light. - This was the proof of concept.

On to the real world, where I am trying to run a string of 16 RGB Neopixels and a seperate string of 16 UV Neopixels. I want them to run a noise pattern, but I would like to dim or brighten each string’s noise pattern off of the rangefinder variable as a whole, individually. I also want the RGB LED string to be warm, a nd keeping a constant H value if you think HSV.

I’m just beginning with FastLED on my RGB string, and I am experimenting with the noise example code, and I’m not getting any sparkle at all, Just solid white. I have set the scale variable all the way to 4011 with no effect.

Any advise?

Lets see if I can remember the specific questions…

1a: Is it possible to brighten or darken the overall brightness of a string, while retaining a noise pattern (basically have the pattern brighten/darken)
1b: Is it possible to constrain a noise based sparkle effect so it doesn’t effect the color, just the luminance of a specific color vector?
2: Is there a simple way to carry the effect, with independent luminance for each of the two strings attached? I needn’t have a second noise generator, I’m happy to use the same noise pattern on each string, however with independent, per-string control of the luminance, based on my rangefinder values as described above.

Can anyone think of similar examples?

https://drive.google.com/file/d/1i5wy5llgal9O7OOrwAPx2yrsbB1DEjY2/view?usp=drive_web

i think fastLED has all the tools you need.

The brightness command would solve 1a,

1b is solved by using CHSV(hue, saturation, value (i.e. brightness)) when setting the pixel colors in your sparkle effect.

not clear what your 3rd questions is.

@Tom_Goode If you post your code to http://gist.github.com even those on mobile phones can view it correctly. Right now it has be downloaded before it can be viewed which is annoying.

Here is the gist. It contains the version of noise.ino that I modified into NoiseExperiment.ino and ultrasonicservofade.ino, my code cobbled together from bits and bobs on the web.

@Mark_Estes thanks, I’m quite sure fast LED can achieve what I want. The problem is with the documentation. In its current form it doesn’t clearly explain how to address a complete chain versus an individual pixel.

This: leds[n] = CHSV(h,s,v); allows me to address one pixel.

You say I can use “brightness” to achieve what I want in 1a - great. How? Can you point me to an easy to understand example. Remember, I want to effect an entire string, without otherwise changing the underlying noise animation that is running on that string.

There is also the problem I’m having with the noise.ino example code. I just get solid colors on a 4x4 matrix (16 led string in reality, but same effect).

Is the small size of the matrix my problem?

@Tom_Goode well to use a string of leds, you must have them in an array, i will assume you called it leds[]. in some subset of that you want a sparkle function that changes in brightness. So. assume you have range of colors for this. We can use random(0,64) if we want that color to be red to orange. We will use 255 for saturation but you could make this a random function as well. then for brightness, pick a target between 0 and 255 and then generate random levels near there…I will call this with a byte called britelevel. We can add a bit of variety to that with a random(64) so…

so to get a range of red to orange leds that are close to a brightness range you selected, this will do the job.

byte britelevel = 128;

for (int i=first_lead; i<last_lead; i++)
leds[i]= CHSV(random(0,64), 255, britelevel+ random(64));

@Tom_Goode said “I’m just beginning with FastLED…” Might be worth checking, have you tried out some of the very basic FastLED examples like RGBCalibrate, FirstLight, and Cylon and got those working successfully? Good to confirm your hardware is working as expected. If yes, then carry on. :slight_smile:

@marmil Thanks for the advice, I did an RGBCalibrate calibrate and found that my pixels are GRB, so things are looking better now that I’ve added a calibration line. I am able to get sensor values and fit them into CHSV coordinates in the example code in the place of the supplied test variable.

@Mark_Estes I will have to wait until tomorrow morning to take a stab at understanding what you’re getting at. I don’t have much programming experience other than some commodore basic I learned 41 years ago as a kid.

I’ll upload a gist of my latest progress which has added modified elements of the noise.ino example and is actually driving a single string of 16 RGB LEDs.

Thanks for the help

I might play around with setTemperature(), as the ideal effect I’m looking for would be analogous to an incandescent lamp dimming. Using CHSV with a fixed H value in the neighborhood of 28-34, sensor derived value for S, and a noise + sensor derived value for V.

Like this, based on the NoiseExperiment.ino example above.

In the line below, average2 is a smoothed sensor read that uses a rolling average of the last 70 cycles of the raw sensor data.

leds[XY(i,j)] = CHSV(31, (noise[i][j]), (average2 + noise[j][i]>>2));

I suppose I could also do a

luma = map(sensorValue, 0, 160, 34, 26);

Fitting the variable “luma” in place of 31 in the leds line just above.

I’ll have to try this later.

Updated the gist with my efforts so far to merge the noise.ino example code with my ultrasonicservofade.ino

It works after a fashion, but I still need to work on the brighness per string problem…

Dual strings are now working

Gist has been updated again… I was dissatisfied with the response from the HC-SR04 at close ranges (I might have a broken sensor) so I added a light sensor with either analog or digital output (high/low). This is feeding pin A0.

There is an if() added to decide on whether to use the ultrasonic sensor or the light sensor depending on the value of sensorValue meeting a threshold.

No, I haven’t slept yet

Here we are so far…

The hardware has been married to the artwork. The tech is left out in the open on purpose.

I have a replacement HC-SR04 on the way, so I’ll swap that sensor out, and add a pair of resistors as a divider on the echo pin. The module outputs 5V logic while the feather is expecting 3.3V on the GPIO.https://youtu.be/5Q8jjH2weeY

@Tom_Goode Thanks for sharing what it all looks like installed with the art. Very mysterious!