The code finally works!
The Catertainer has 10 taunts, and every minute, if it isn't played with, it will say one of the taunts.
Here is an example of one of the taunts.
Catertainer Circuit from Mouse & the Billionaire on Vimeo.
I finally got the Wee from Sparkfun, so I'll be transferring the whole circuit to the new (much smaller) circuit, soon.
fun!
// 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 = 7; // Assign our pins
int recordPin = 0;
int playPin = 8;
int rangeFinder = 0;
int vPin = 9; // 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() {
analogWrite(playPin, ON);
delay(50);
analogWrite(playPin, OFF);
// Get the next taunt ready
long taunt = random(1, 10); // choose a random taunt
long i = 0;
do {
Serial.println(i);
analogWrite(forwardPin, ON);
analogWrite(playPin, OFF);
delay(50);
analogWrite(forwardPin, OFF);
i++;
} while (i < taunt);
}
void gettinScared() {
analogWrite(vPin, 255);
analogWrite(forwardPin, 255);
analogWrite(recordPin, 255);
delay(5);
analogWrite(vPin, 0);
}
void next() {
analogWrite(playPin, 255);
analogWrite(forwardPin, 0);
analogWrite(recordPin, 255);
delay(50);
analogWrite(playPin, 0);
analogWrite(forwardPin, 255);
delay(500);
analogWrite(playPin, 255);
delay(3000);
analogWrite(forwardPin, 0);
}
Comments
You can follow this conversation by subscribing to the comment feed for this post.