i did something like that with a servo myself. i try to keep it simple here, to see if this is going your direction, feel free to ask if you need more detailed infos on this matter.
#1 the motor: first step was to take the motor and program it with the values directly to move to its start and end position. that done i knew i could make the motor move.
#2 the rotary encoder: next step was to take a rotary encoder and read its output values in the serial monitor. this is explained in the basic arduino lessons. (i did this in a complete new setup/project, just to get this working and understanding without interference of the first step)
#3 value conversion:
take the rotary encoder values and convert them to the needed motor values:
“rotary encoder value” diveded through “needed motor value” = “conversion factor”
with that factor you can now convert the rotary encoder values in the values you need to give to the motor his needed values:
“rotary encoder value” diveded through “conversion factor” = “needed motor value”
example: in my case the rotary encoder value was ranging from “0” to “1023” which had to be converted to a motor value range of “0” to “180”, so my factor was 1023:180=5.683333333333333
#4 put it all togehter:
put together the motor control and the reading of the rotary encoder and all comes togehter:
everytime i turn the rotary encoder now, the value will be given to the motor as its diveded state:
full left end rotary position = 0/5.683333333333333 = 0 for servo.write
middle rotary position = 512/5.683333333333333 = ~90 for servo.write
full right end rotary position = 1023/5.683333333333333 = 180 for servo.write
… which gave my servo a perfect left, middle, right position of its servo arm.
that basic principle can be refined in a lot of ways, for example cutting out only a limited range of the way the rotary encoder can be turned.
int eingang= A0;
int sensorwert = 0;