Following on from the Bluetooth controlled LEDs I wanted to see if I could get a string of WS2812B lights to react to their environment.
I selected the Adafruit TCS34725 colour sensor because a) it was well documented, and I didn’t want to mess around too much.
I found some code samples by duct soup showing how to get an RGB reading from the sensor and used as is, talking to the sensor over the i2c interface. The only addition I made was to convert the RGB value to HSV, so that I could drive the brightness up by increasing V, then convert back to RGB before pushing the value to the WS2812B light strip. I also added an increment value to slow the colour transitions down and protect against noisy or inaccurate sensor values, which did seem to occur. I also initialise the sensor LED to be off, as the application we have in mind is really interested with the ambient light in the room, not the incident light from any particular object.
The code is all here on GitHub.