I have a VL53L0X TOF-sensor (50 - 1000 mm reliable distance detection) and want

I have a VL53L0X TOF-sensor (50 - 1000 mm reliable distance detection) and want to visualise proximity with a 1m 144 LED APA102C strip.

I want to translate distance detected to LEDs lit, while also smoothly changing the colours according to the visible spectrum of light https://upload.wikimedia.org/wikipedia/commons/d/d9/Linear_visible_spectrum.svg where below 50 mm the strip is black (off) and above 1000mm black (off) also.

How would I go about this, in terms of FastLED functions necessary? To begin with, a simple black to blue to red to black transition would also be ok.

Thanks for pointing me in the right direction!

Thanks, fill_solid & ColorFromPalette I have not thought about. So with switch case it should be done as a state machine…

@Jason_Coon - is there some reason why my first post to Andreas is not being shown publicly?

Here it is again:

@Andreas_Hopf - Have you looked at the Adafruit vl53l0x tutorial:

and their library for this:

The library produces a variable that is the number in mm. You can use the Arduino Switch Case statement with this variable:

http://arduino.cc - Arduino Reference

along with FastLED’s fill_solid function or the ColorFromPalette function to accomplish what you want to do.
Arduino Reference

@Ken_White For whatever reason, I see the red spam flag to the top left of your post and a subheader in read “Removed as spam and only visible to you” - very odd. Maybe the dirty 7-letter word “Arduino” was the culprit ; )

@Andreas_Hopf Check out gradient color palettes. You can make one to match the visible spectrum link you shared.
https://github.com/FastLED/FastLED/wiki/Gradient-color-palettes

You will also probably use the Arduino map function for scaling the distance sensor’s value to your 144 pixels.
https://www.arduino.cc/reference/en/language/functions/math/map/

I made something like this myself, just to see how the TOF sensor worked. I started out using the strip as a distance meter – basically, mapping the TOF distance from 50-1000 to the length of the strip (say, 0 to 144), and then lighting up that number of LEDs to some fixed color. It’s simple, but fun to play with

Ok, thanks, first, I have to get the VL53L0X working reliably in continuous mode, making a measurement every 500 milliseconds.

@Andreas_Hopf Which library are you using to communicate with the VL53L0X? Check out this one: it’s easy to use and has good examples.
https://github.com/pololu/vl53l0x-arduino

I’m using the Pololu library, because even Adafruit, whose breakout-board I’m using, says that Pololu’s is much smaller, faster and better. I got the basics working and first of all try to have a simple buzzer change its buzz repetition frequency according to distance, just like on a car parking assist.

That’s how far I got, the sensor is calibrated to +/- 1 millimetre and the buzzer beeps slower or faster according to distance. Just in case, the code as it is at the moment https://forum.arduino.cc/index.php?topic=557894.0

Now, I have to map the distance to my 1 metre LED strip, the way Marc Miller suggested, making a gradient palette and then accessing it according to distance measured. Seems daunting for a beginner, but should hopefully be educational ; )

Bit of a project diary here, but may be useful for other beginners that want interaction between sensor outputs and LED strips. Found https://gist.github.com/kriegsman/8281905786e8b2632aeb and now, having defined a fairly good visible colour spectrum palette, try to find out how to simplify what I need for using only one palette as in my case. Phew, this is trickier than I thought, although I’m learning in parallel with Jack Purdum’s “Arduino C For Beginners” book.

@Andreas_Hopf - Check out:

and lines 61 thru 69. This is a great illustration on how to use the ColorFromPalette function especially if you want to use only one palette.

@Andreas_Hopf - Here are examples of mine that uses only one palette at a time with a customized ColorFromPalette function:

see line 271 in Chase.h and line 61 or 62 in Time_performance.h

Also see:

see lines 132, 133 and lines215 thru 231.

Ok, thanks for the samples; still struggling a bit with polling the sensor and beeping; something is off there still, as if the beeps are not linearly accelerating as the distance shortens, as if there were discrete plateaus. I have to get that right first, because the in my case rather simple LED reaction depends on the distance measured.