## Kitteh

Here is the Kitteh pumpkin, also known as the Cat-O-Lantern.

It is very temperamental and has a lot to say about physical contact.

It has two individual LEDs for eyes, driven by pin 2, eight LEDs in series for the mouth driven by pin 5, and a PING ultrasonic sensor driven by pin 7.

The PING ultrasonic sensor discriminates between two states.

The ground state is when there is a distance of at least 50cm between the PING sensor and anything. In the ground state, the eyes blink randomly and the mouth pulsates slowly.

When something comes closer than 50cm, the active state takes over, making the eyes blink rapidly and the mouth pulsate fast.

It returns to normal once the distance of 50cm is restored.

```//-------------------------------------------
// Kitteh
//-------------------------------------------

int randOn 	= 0;
int randOff 	= 0;
// int eyePins[3] = {2, 3, 4};
int eyepins    = 2;
int mouthPins  = 5;
int brightness = 0;
int brightnessActive = 0;
int time 	= 50;
int pingPin 	= 7;
// int i = 3;

/*------------------------------
Setup
------------------------------*/
void setup()
{
Serial.begin(9600);

pinMode(eyepins, OUTPUT);

pinMode(5, OUTPUT);
}

/*------------------------------
Loop
------------------------------*/
void loop()
{
int cm = ping();

//PASSIVE STATE
if(cm > 50)
{
//EYES
//      for(int i = 0; i <3; i++)

//MOUTH
}
//ACTIVE STATE
else
{
//EYES
//    for(int i = 0; i <3; i++)
eyeChase(eyepins, time);

//MOUTH

//    Serial.print(i);
}

}

/*________________________________________________

Ping
________________________________________________*/
long ping()
{
int duration, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

cm = microsecondsToCentimeters(duration);

Serial.print(cm);
Serial.print("cm");
Serial.println();

delay(100);
return cm;
}
/*________________________________________________

MicroSeconds To Centimeters
________________________________________________*/
long microsecondsToCentimeters(int microseconds)
{
return microseconds / 29 / 2;
}

/*________________________________________________

________________________________________________*/
void eyeBlink(int pin, int randOn, int randOff)
{
randOn = random (300, 6000);
randOff = random (50, 140);

digitalWrite(pin, HIGH);
Serial.print("On = ");
Serial.print(randOn);
Serial.print(", ");
delay(randOn);

digitalWrite(pin, LOW);
Serial.print("Off = ");
Serial.print(randOff);
Serial.print(", ");
delay(randOff);
Serial.println();
}

/*________________________________________________

Eye Chase
________________________________________________*/
void eyeChase(int pin, int duration)
{
digitalWrite(pin, HIGH);
delay(duration);
digitalWrite(pin, LOW);
delay(duration);
}

/*________________________________________________

________________________________________________*/

{

analogWrite(pin, brightness);
if (brightness == 0 || brightness == 255)
{

}
delay(20);
}

/*________________________________________________

Mouth Active
________________________________________________*/
/*void mouthActive(int pin, int brightnessActive, int fadeAmountActive)

{

analogWrite(pin, brightnessActive);