Triggering a servo to repeat an action

Use a rotary encoder to increment/decrement the pill count variable.  Limit the high and low values with code.  Employ the encoder's built-in pushbutton, or a discrete button, to start the dispense cycle.