Autoblink

The eyes now blink automatically. They will flit closed semi-randomly with minimum and maximum time spans between blinks. When the puppeteer wants to take over, they can be switched to manual mode.

How about some code!

unsigned long last_time = millis();
unsigned long time = millis();
unsigned long autoblinkdelay=1000;
unsigned int blinkingnow=0;
void loop(){

//do some other things in the loop here//

//now, the blinking stuff:

  time = millis();  //get the current time in milliseconds
  if ((time-autoblinkdelay)>last_time){
    blinkingnow=autoblink_duration;  //fill up the blinking timer, when it reaches zero the eye will open back up
    autoblinkdelay=random(autoblink_mintime,autoblink_maxtime);  //randomly select how long until the next blink
    last_time=time; //holder for comparing times in the next iteration of the loop
  }
  if(blinkingnow){  //is "blinkingnow" empty? if not, keep eye closed
    blinkingnow--;
    eyes_output=eyes_servo_closed;
    soft_servo(EYES_SERVO,eyes_servo_closed);
  }
  else{  //open the eye!
    eyes_output=eyes_servo_open;
    soft_servo(EYES_SERVO,eyes_servo_open);
  }
  delay(4); //delay to let the servo have time to get where it goes
}
Advertisements

2 Responses to “Autoblink”

  1. I’ve been looking for something like this site for a really long time! I’ve been trying to find tutorials on how to do eye mechs with servos and an arduino and there’s not a lot out there other than very basic left-right movement.

    The blog format of the site makes it a little hard for people to find specific information, but thank you for sharing your experience.

  2. I’ve been able to pretty easily control a servo with a wiimote nunchuck using the arduino now. What I can’t find anywhere is parts for an eye mechanism. I don’t have access to a machine shop, and I can’t just hand mold something myself with polymers since it has to move very smoothly.

    Every search I’ve done online for eye hinges or eye mechs results in very expensive eye-kits that include the microcontroller etc (which is extra annoying since I got the microcontroller part worked out for like 30 bucks).

    Do you know where to get the mechanical pieces for moving eyes? I’m assuming you probably machine your own, but that’s just not possible for me, and I’m willing to work around whatever I can find.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: