Attaching a potentiometer to a motor to stutter

I want to attach two motor shafts to potentiometers so that the motor would only travel a very short distance back and forth in an oscillating motion. (think windshield wipers or walking legs) .
Any help would be greatly appreciated. I am thinking something like this…


startMotor(motorPort, speed);
untilPotentiometerGreaterThan(position, sensorPort);
startMotor(motorPort, -speed);
untilPotentiometerLessThan(position, sensorPort);


(best way possible to do it)

Are you trying to achieve a rapid oscillation or a more slow rate?

I would try a simple P-loop,

rapid … like a jitterbug

A kind of walking machine… the motors needs to go a very short distance then return … oscillating
I am using VEX natural languagePLTW

I think you should use a crankshaft to produce a reciprocating motion like in a car engine.

Rapidly reversing a motor will make it overheat quickly, and if your Walker’s legs are too heavy, you wont be able to achieve rapid oscillations at all