Skip to main content
replaced http://electronics.stackexchange.com/ with https://electronics.stackexchange.com/
Source Link

The biggest problem is that by forcing the code to use integral inches you've restricted it to 31 discrete values. And since the brightness response of a PWMed LED is non-linearthe brightness response of a PWMed LED is non-linear you effectively have very large steps in brightness when the LED is dim.

pulseIn() has much more flexibility with regards to its range so use the raw value directly instead of converting it to "pretty" values.

val = map(pulse, ..., ..., 0, 255);

The biggest problem is that by forcing the code to use integral inches you've restricted it to 31 discrete values. And since the brightness response of a PWMed LED is non-linear you effectively have very large steps in brightness when the LED is dim.

pulseIn() has much more flexibility with regards to its range so use the raw value directly instead of converting it to "pretty" values.

val = map(pulse, ..., ..., 0, 255);

The biggest problem is that by forcing the code to use integral inches you've restricted it to 31 discrete values. And since the brightness response of a PWMed LED is non-linear you effectively have very large steps in brightness when the LED is dim.

pulseIn() has much more flexibility with regards to its range so use the raw value directly instead of converting it to "pretty" values.

val = map(pulse, ..., ..., 0, 255);
Source Link

The biggest problem is that by forcing the code to use integral inches you've restricted it to 31 discrete values. And since the brightness response of a PWMed LED is non-linear you effectively have very large steps in brightness when the LED is dim.

pulseIn() has much more flexibility with regards to its range so use the raw value directly instead of converting it to "pretty" values.

val = map(pulse, ..., ..., 0, 255);