#include<Servo.h>
Servo servo1;
Servo servo2;
int min = 500;
int max= 2500;
int smoother = 10;
int blink_smoother =2;
int eyeMin = 0;
int eyeMax = 130;
int hold = eyeMin+eyeMax/2;
void setup() {
servo1.attach(3, min, max);
servo1.write(0);
servo2.attach(5, min, max);
servo2.write(0);
delay(5000);
}
void loop() {
eyes(servo1, servo2);
//motor2(servo2);
}
void eyes(Servo servo_h, Servo servo_v){
blink(servo_v,blink_smoother);
moveUp(eyeMax, servo_h,smoother);
moveDown(eyeMin, servo_h,smoother);
moveUp(hold, servo_h,smoother);
blink(servo_v,blink_smoother);
delay(5000);
moveDown(eyeMin, servo_h,smoother);
moveUp(eyeMax, servo_h,smoother);
moveDown(hold,servo_h,smoother);
blink(servo_v,blink_smoother);
delay(5000);
moveDown(eyeMin, servo_h,smoother);
}
void blink(Servo servo_v, int smoother){
moveUp(90, servo_v, smoother);
moveDown(0, servo_v, smoother);
}
void moveUp(int angle, Servo servo, int smoother){
for(int i = servo.read();i<=angle && i<180 ;i++){
servo.write(i);
delay(smoother);
}
}
void moveDown(int angle, Servo servo, int smoother){
for(int i = servo.read();i>=angle && i>=0 ;i--){
servo.write(i);
delay(smoother);
}
}