Video: http://www.youtube.com/watch?v=NHiuERHH5UQ
Processing code:
import ddf.minim.*;
AudioPlayer player1;
Minim minim;
Serial port;
String file1="cat_screech.wav";
int playing=0;
void setup()
{
size(512, 200, P2D);
port = new Serial(this, "COM3", 9600);
minim = new Minim(this);
player1 = minim.loadFile(file1, 2048);
}
void draw()
{
}
void stop()
{
player1.close();
minim.stop();
super.stop();
}
void serialEvent (Serial p) {
String inString = port.readStringUntil('\n');
if (inString != null) {
println(inString);
int value=int(trim(inString));
if(value==1 )
{
println("play");
player1 = minim.loadFile(file1, 2048);
player1.play();
delay (200);
}
}
}
ARDUINO CODE:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 180; // variable to store the servo position
int counter=0;
int potPin=0;
int val=0;
void setup()
{
Serial.begin(9600);
myservo.attach(7); // attaches the servo on pin 7 to the servo object
myservo.write(pos);
}
void loop()
{
val = analogRead(potPin);
if (val > 950) {
if (counter<3) {
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
Serial.println(0);
delay(5); // waits 5ms for the servo to reach the position
}
delay(200);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 5ms for the servo to reach the position
}
delay(200);
counter=counter+1;
}
} else {
counter=0;
}
}