I had a similar problem converting a linear input from a Nextion slider into a logarithmic value for PWM control of white lights. If I left the relationship linear then the change in brightness looked wrong for changes of the slider position, due to the eye’s response to changes in brightness being logarithmic.

I used this:

```
unsigned char white_scale (unsigned char set) {
return (unsigned char)round((1 - log10(10 - (double)set * 9 / 254)) * 255);
}
```

To provide the logarithmic value, which is satisfactory in the sense that the brightness of the light changes in what appear to be a linear fashion with the slider movement.

The function returns a logarithmically adjusted value based on the value of set, which is 8 bits.

I’m sorry but I can’t offer an explanation for the exact maths involved, it was too long ago and I have help from a friend who is much better at both maths and programming than I am.

Try the function and see if it does what you need.