Description:
I created a stuffed dog that will walk when you press the force sensor. It also barks when it walks.
Watch at http://www.youtube.com/watch?v=_iZie2M8x8M.
Materials:
-
Force sensitive resistor
-
DC motor
-
TIP120 transistor
-
1N4004 diode
-
1k ohm resistor
-
10k ohm resistor
-
Fabric
-
Thread
-
Stuffing
-
Rubberbands
Processing Code:
/* Jennifer Wang
* HW 6
* October 11, 2011
*
* Walk the dog bark
* Make the dog bark when the dog starts walking (sensor turned on)
*
* Use with arduino potControlsMotor code
*
*/
import ddf.minim.*;
import processing.serial.*;
Minim minim;
AudioPlayer bark;
AudioInput input;
AudioOutput out;
float gain = -60; // gain between -60 and 5
Serial port;
int sensorVal; // value from force sensor
// ** calibrate the low and high values of the sensor to get full range **
int sensorLow = 100;
int sensorHigh = 490;
void setup() {
println(Serial.list()); // List COM-ports
//select second com-port from the list
port = new Serial(this, Serial.list()[0], 9600);
size(100, 100);
minim = new Minim(this);
bark = minim.loadFile("Sound Effect - Dog Barking 04.wav");
input = minim.getLineIn();
out = minim.getLineOut(); // returns a stereo line out with buffer size of
// 1024 samples that plays 16 bit audio at 44100 Hz sample rate
bark.loop();
bark.setGain(gain);
}
void draw() {
bark.setGain(gain);
}
void stop() {
// the AudioPlayer you got from Minim.loadFile()
bark.close();
// the AudioInput you got from Minim.getLineIn()
input.close();
minim.stop();
// this calls the stop method that
// you are overriding by defining your own
// it must be called so that your application
// can do all the cleanup it would normally do
super.stop();
}
void serialEvent(Serial p) {
// get the ASCII string:
String inString = port.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to integer
sensorVal = int(inString);
// bark if sensor is turned on (in transition fron off to on)
if (sensorVal > sensorLow & gain == -60) {
println("bark");
//bark.unmute();
gain = 5;
}
// bark if sensor is turned off (in transition from on to off)
else if (sensorVal < sensorLow & gain == 5) {
println("no bark");
//bark.mute();
gain = -60;
}
}
}