The circuit inside the Catertainer has been miniaturized. Check it out!
It doesn't get much more compact than that. There's a switch to turn the bad boy on, and a button the side of the container to trigger the sound clips for exhibition purposes. Next step... fur!
Read below for the final code
// Catertainer!
// M Bethancourt
// 2008
#define NUMREADINGS 25
int readings[NUMREADINGS]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int forwardPin = 3; // Assign our pins
int recordPin = 0;
int playPin = 6;
int rangeFinder = 0;
int vPin = 10; // vibrating motor
int OFF = 255;
int ON = 0;
boolean catNear = false;
int counter = 0;
int closeValue = 0; // variable to hold cat distance
void setup()
{
// Turn all windbond pins off
analogWrite(forwardPin, OFF);
analogWrite(playPin, OFF);
Serial.begin(115200); // setup serial
for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0; // initialize all the readings to 0
}
void loop() {
Serial.println(counter); // how much time has elapsed since I was played with?
catNear = readIR();
if (catNear != true){ // if there is no cat around
if (counter >= 20000){ // and I have been left alone for a while
taunt(); // I taunt!
Serial.println("Taunt!");
counter = 0; // reset the counter
}
counter++;
} else { // Else, I was recently played with
counter = 0; // so let's reset the counter
}
}
boolean readIR() {
total -= readings[index]; // subtract the last reading
readings[index] = analogRead(rangeFinder); // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index
boolean playedWith = false;
if (index >= NUMREADINGS) // if we're at the end of the array...
index = 0; // ...wrap around to the beginning
average = total / NUMREADINGS; // calculate the average
// Serial.println(average); // send it to the computer (as ASCII digits)
closeValue = average;
if(closeValue > 150){
gettinScared();
catNear = true;
} else {
catNear = false;
}
return catNear;
}
void stop() {
analogWrite(forwardPin, OFF);
analogWrite(recordPin, OFF);
analogWrite(playPin, OFF);
analogWrite(vPin, 0);
}
void taunt() {
digitalWrite(playPin, ON);
delay(50);
analogWrite(vPin, 255);
delay(5);
digitalWrite(playPin, OFF);
analogWrite(vPin, 0);
// Get the next taunt ready
long taunt = random(1, 10); // choose a random taunt
long i = 0;
do {
Serial.println(i);
digitalWrite(forwardPin, ON);
digitalWrite(playPin, OFF);
delay(50);
digitalWrite(forwardPin, OFF);
i++;
} while (i < taunt);
}
void gettinScared() {
digitalWrite(vPin, HIGH);
digitalWrite(forwardPin, HIGH);
digitalWrite(recordPin, HIGH);
delay(5);
analogWrite(vPin, 0);
}
void next() {
digitalWrite(playPin, HIGH);
digitalWrite(forwardPin, 0);
digitalWrite(recordPin, HIGH);
delay(50);
digitalWrite(playPin, 0);
digitalWrite(forwardPin, HIGH);
delay(500);
digitalWrite(playPin, HIGH);
delay(3000);
digitalWrite(forwardPin, 0);
}
Comments