Here's the final video of Meowzers working, you’ll see us operating the device using a sketch that I wrote in Processing that features a cute cat cartoon cat that works as a “cursor” that directs the action of the two servos and triggers the laser pointer we embedded into the mouths of one of the four mouse heads that adorn the cat scratching post we modified. Moving the cat icon vertically activates the servo that controls the movement of a feather teaser, causing it to dip and rise to bait the cat to chase it. Moving the cat icon horizontally activates the servo that spins the crown of the scratching post, causing the mouse heads attached to the four posts emanating from the center post to shake in a wild fashion. Pressing the mouse on the computer triggers the laser pointer we embedded into one of the mouse heads.
Here’s the Processing Code:
import processing.serial.*;
Serial port; //Create object from Serial class.*;
PImage Cat1;
PImage Cat2;
void setup() {
imageMode(CENTER);
size (700,700);
Cat1 = loadImage(”Cat.jpg”);
Cat2 = loadImage (”Cat2.jpg”);
frameRate(30);
//Open the port that the board is connected to and use the same speed (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
background (255);
//ellipse (mouseX, mouseY, 10,10);
//change color
float newmouseX = map (mouseX, 0, width, 0, 254);
float newmouseY = map (mouseY, 0, height, 0, 254);
port.write((byte)255); //start byte
port.write((byte)newmouseX);
port.write((byte)newmouseY);
if (mousePressed){
image(Cat2, mouseX, mouseY);
port.write((byte)4);
}
else {
image(Cat1, mouseX, mouseY);
port.write((byte)0);
}
}
And the Arduino code:
#include
Servo servoMotor1;
Servo servoMotor2;
int servo1 = 0; //Data received from the serial port
int servoPin1 = 9; //Set value servoPin to pin 9
int servo2 = 0; //Data received from the serial port
int servoPin2 = 10; //Set value servoPin to pin 9
int button = 0;
int buttonPin = 2;
void setup(){
servoMotor1.attach(servoPin1); //Sets pin as OUTPUT
servoMotor2.attach(servoPin2); //Sets pin as OUTPUT
pinMode(buttonPin, OUTPUT);
Serial.begin(9600); //Start serial communication at 9600bps
}
void loop()
{
if (Serial.available()>= 4){ //If 4 bytes are available to read,
int inByte = Serial.read ();
if (inByte == 255) {
servo1 = Serial.read(); //read serial and store it as val
servo1 = map(servo1, 0, 254, 179, 0);
servo2 = Serial.read(); //read serial and store it as val
servo2 = map(servo2, 0, 254, 179, 0);
button = Serial.read(); //read serial and store it as val
servoMotor1.write (servo1);
servoMotor2.write (servo2);
if (button == 4){
digitalWrite (buttonPin, HIGH);
}
else{
digitalWrite (buttonPin, LOW);
delay(25);
}
}
}
}
We consider this project to be a HUGE success, especially considering the little experience we had with programming prior to this class. We’re extremely grateful to all those who aided us, and our special thanks goes out to:
Jeremy Rotzstain, whose quick tutorial on Processing made our control device possible;
Adam Parrish, who helped us get our feet wet with Processing with his help session;
Todd Holoubek and Rory Nugent, whose suggestions on the P Comp side were invaluable;
Rob Faludi, whose last minute adjustment to our Arduino code literally calmed our jitters by solving the problem of our shaky servos;
Tigger Ryan, who did a wonderful job as our “test cat”;
our classmates, whose creativity, ambition, and brilliance inspired our efforts;
and finally, our teacher Scott Fitzgerald, who is one of the best teachers I've ever had and whose patience, knowledge, generosity, bad jokes and incisive feedback made this class so awesome.
I also have to give props to my PCOMP partner throughout the course, Gordie, whose woodworking/shop skills as well as understanding of electronics far surpass mine. He was great to work with, easygoing and up for any challenge and he always made the learning experience fun.

No comments:
Post a Comment