I want to adjust my smart bulb according to the current average color on the computer screen. I'm using image-average-color and screenshot-desktop libraries to take screenshot and get the average color value of that image. Finally, there's node-yeelight-wifi library to control the light blub. My problem is I don't know how to take screenshots, find the average color and then send command to bulb at regular intervals. It should, for example, change colors according to movie that playing on the screen. What i want is create a "main" function and run that every 2 secs. I couldn't do it with setInterval because i can't pass the "light" parameter all the way down to setRGB
NOTE: All functions work if they are standalone, there's no problem with the libraries
const screenshot = require("screenshot-desktop");
const average = require("image-average-color");
const Lookup = require("node-yeelight-wifi").Lookup;
let look = new Lookup();
look.on("detected", async (light) => {
if (light.id == "mybulb") {
setInterval((light) => {
screenshot()
.then((img) => {
average(img, (err, color) => {
if (err) throw err;
light
.setRGB(color)
.then(() => {
console.log("success");
})
.catch((error) => {
console.log("failed", error);
});
});
})
.catch((err) => {
console.log(err);
});
}, 3000);
}
});