The Talking Tissue Box

So far it’s not working quite the way I want it to yet. Had problems getting Processing to read my Serial messages properly when I coded in Arduino, so in frustration, I used Firmata and controlled Arduino through Processing.

Except my talking box still isn’t working the way I want to yet. I think I bent the sensor too many times…. Seemed to work a bit better after I switched sensor.

Firmata is included with Arduino’s examples, so I’m not going to include it here. Here’s the Processing code that is still buggy:

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;

int tongueVal;

Timer timer;

Minim minim;

AudioPlayer[] tongue;
AudioPlayer[] untouched;

int uInt;
int tInt;

void setup() {
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[17], 57600);
for (int i = 0; i <= 13; i++) arduino.pinMode(i, Arduino.INPUT);

minim = new Minim(this);

tongue = new AudioPlayer[4];
tongue[0] = minim.loadFile(“drrr.mp3”);
tongue[1] = minim.loadFile(“ouch.mp3”);
tongue[2] = minim.loadFile(“stoptouching.mp3”);
tongue[3] = minim.loadFile(“pervert.mp3”);

untouched = new AudioPlayer[4];
untouched[0] = minim.loadFile(“hi.mp3”);
untouched[1] = minim.loadFile(“pokeme.mp3”);
untouched[2] = minim.loadFile(“yoohoo.mp3”);
untouched[3] = minim.loadFile(“hello.mp3”);

timer = new Timer(6000);
timer.start();
}

void draw() {

tongueVal = arduino.analogRead(0);
println(tongueVal);

// if untouched
if (tongueVal > 65 && tongueVal < 68) {
if(timer.isFinished()) {
uInt = int(random(4));
untouched[uInt].play();
timer.start();
untouched[uInt].rewind();
}
}

// if tongue is touched

else if (tongueVal < 65 || tongueVal > 68) {
untouched[uInt].pause();
tInt = int(random(4));
tongue[tInt].play();
delay(1000);
tongue[tInt].rewind();
}
}

void stop() {
super.stop();
}

class Timer {

int savedTime; // When Timer started
int totalTime; // How long Timer should last

Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}

// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}

// The function isFinished() returns true if 5,000 ms have passed.
// The work of the timer is farmed out to this method.
boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *