Light Intensity to PWM Value

Our eyes don’t see light as linear. Instead, to see it “one step brighter”, it has to become 2x as bright. And the next x2 increment will be seen as another similar step. In other words, our eyes see on a logarithmic scale. Or exponential, depending on how you look at it.

For my electronics projects I often have the need to take the linear position of a potentiometer, and translate it to an exponential value I can use to PWM some LEDs. I had some Python scripts scattered around to do this, but figured it was more convenient to have a web-based tool instead. So, here it is!


The above code is in C, which I use for my microcontrollers. You can use the above code in your project as-is, or just copy the values and write the rest yourself.

The generated code (above) is licensed CC0. The generator itself is licensed GPL.