Cat Ear Code

This is the Arduino code for running the cat person ears. The circuit was simply three switches, one for each paw and one for the petting sensor, and a pair of servos. The code just checks each sensor and moves the corresponding ear.

#include <Servo.h>

//Servo pins
#define rightpaw 6
#define leftpaw 7
#define pet_sense 8

//Ear positions
#define r_up 95
#define r_down 160
#define l_up 180-r_up
#define l_down 180-r_down

Servo leftear;  // create servo object to control a servo
Servo rightear;

int pos = 0;    // variable to store the servo position

void setup()
{
  leftear.attach(9);  // attach the ear servos
  rightear.attach(10);

  pinMode(7, INPUT);

  leftear.write(l_up);
  rightear.write(r_up);
}


void loop()
{
  if(digitalRead(rightpaw) == HIGH)
  {
    rightear.write(r_down);
  }
  else
  {
    rightear.write(r_up);
  }

  if(digitalRead(leftpaw) == HIGH)
  {
    leftear.write(l_down);
  }
  else
  {
    leftear.write(l_up);
  }

  if(digitalRead(pet_sense) == HIGH)
  {
    leftear.write(l_down);
    rightear.write(r_down);
    delay(1500);
  }
}