meg768 / rpi-matrix

2 stars 2 forks source link

setting pixel brightness #1

Closed buggedcom closed 5 years ago

buggedcom commented 5 years ago

Thank you for this library.

Is there any way that you know of to set pixel brightness?

meg768 commented 5 years ago

This can only be done during the initial configuration by using the led-brightness property. Otherwise you have to adjust pixel brightness yourself by changing the color.

buggedcom commented 5 years ago

by changing the color

You mean via sliding the colour towards black I guess?

Also, what version of node have you managed to get it working on? I've only managed to get everything to compile with 8.16

meg768 commented 5 years ago

Yes, by changing the pixel color.

I am currently running node 11.15.0...

buggedcom commented 5 years ago

In case anyone else needs a function to slide the pixel to black you can use this as Color is already imported by rpi-matrix.

const black = Color.rgb(0, 0, 0);
function setLightPercentage(col, p) {
    const black_level = (100 - p)/100;
    const darkened = col.mix(black, black_level);
    return darkened.rgb().object();
}

It's not perfect but does the job ok.