It's commonly desired to control the position of a servo so it moves from a minimum position to a maximum position when the pot is moved from one extreme to the other and the ADC goes from 0-255.
The maths for using READADC is as follows -
The MIN_SERVO and MAX_SERVO can be numeric constants ( directly in the code or defined by SYMBOL commands ) or values held in byte or word variables.
When the full pot range is between MIN_POT and MAX_POT rather than 0 and 255 the maths becomes -
Again, MIN_POT and MAX_POT can be numeric constants ( directly in the code or defined by SYMBOL commands ) or values held in byte or word variables.
The maths for using READADC is as follows -
Code:
ReadAdc POT, b0
b1 = MAX_SERVO - MIN_SERVO * b0 / 255 + MIN_SERVO
Servo SERVO_PIN, b1
When the full pot range is between MIN_POT and MAX_POT rather than 0 and 255 the maths becomes -
Code:
ReadAdc POT, b0
b1 = MAX_POT - MIN_POT
b1 = b0 Min MIN_POT - MIN_POT Max b1 * 255 / b1
b1 = MAX_SERVO - MIN_SERVO * b1 / 255 + MIN_SERVO
Servo SERVO_PIN, b1