So, I understand that the sensor has an analog output that depends on the distance. According to the readme of the repo you linked, the distance (in cm) is given as : Distance = 29.988 X POW(Volt , -1.173)
When you read the voltage at the analog input with Puredata using [adc~ 3]
, the range is 0:1, and corresponds to input voltages in the range 0:4.096V. Therefore, in order to convert the [adc~]
value to Volt, you need to multiply it * 4.096
. Then you can use that value in the formula above. In Pd terms, this means:
with discrete operators:
[adc~ 3]
|
[*~ 4.096]
|
[pow~ -1.173]
|
[*~ 29.988]
|
or using [expr~]
:
[adc~ 3]
|
[expr~ 29.988 * pow($v1 * 4.096, -1.173)]
|