You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

import processing.serial.*;
import processing.sound.*;
SoundFile[] soundfile = {null,null,null,null,null,null};
Serial myPort;
String dataIn = "";
int linefeed = 10;
int currentLang = 0;
String[] langs = {"NONE","Italian","English","Spanish","German","French"};
void setup() {
size(600, 400);
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
for(int i=0; i<langs.length; i++) {
println("Loading language file: "+langs[i]+".aiff");
soundfile[i] = new SoundFile(this, langs[i]+".aiff");
}
println("Ready!");
}
void draw() {
background(0);
float sw = textWidth(langs[currentLang]);
fill(255);
stroke(255);
textSize(16);
textAlign(CENTER, CENTER);
text("Selected language:", width/2, (height/2)-50);
textSize(22);
text(langs[currentLang], width/2, height/2);
}
void serialEvent(Serial thisPort) {
if(myPort.available() > 0) {
dataIn = myPort.readStringUntil(linefeed);
if (dataIn != null) {
String[] split = dataIn.split("\t");
currentLang = parseInt(trim(split[1]));
for(int i=0; i<langs.length; i++) {
soundfile[i].stop();
}
soundfile[currentLang].play();
//println(dataIn+" - "+split[0]+" - "+split[1]+" -> "+currentLang);
}
}
}