Best code solution

Hello, I need a little help here. I have made a mask with moving eyes. I used servo and ultrasonic range detector.

Everything works fine except I want to upgrade the code and looking for best solutions. What I want. Write a code where eyes moves just a little bit, but much fastest ( like scared) when object moves closer, but moves on a bigger angle when object moves further. I could use if else, but this seems a bit frustrating for me. Any ideas are

What have you tried ?

Something like

if (range < something)
{
  //code here to move the eyes fast
}
else
{
  //code here to move the eyes slowly
}

why don't you write a generic routine that moves the servo to some position at a specified rate.

build on that with another routine that moves between two positions at a specified rate possibly some limited number of times

build on that with routines to moves the eyes to express some emotion