I'm creating a program that takes serial information from an ultrasonic sensor/arduino and sends it to processing, which will play either crickets.mp3 or growl.mp3, depending on the value of the input.
crickets.mp3 is supposed to play if the value is <10 growl.mp3 is supposed to play if the value is >10
As is, the code will play growl.mp3, but not crickets.mp3
import processing.serial.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player, player2;
Serial myPort; // Create object from Serial class
String dataFromArduino; // Data received from the serial port
String convertedDataFromArduino;
boolean soundactivated = false;
boolean sound2activated = false;
void setup() {
size(640, 480);
minim = new Minim(this);
player = minim.loadFile("crickets.mp3");
player2 = minim.loadFile("growl.mp3");
printArray(Serial.list());
String portName = Serial.list()[4]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
}
void draw() {
player.pause();
dataFromArduino = myPort.readStringUntil('\n'); // read it and store it in message
if (dataFromArduino != null) {
convertedDataFromArduino = trim(dataFromArduino);
println(convertedDataFromArduino);
//Music calls
if (int(convertedDataFromArduino) < 10 && (soundactivated == false)) {
player.loop();
println("crickets");
soundactivated = true;
sound2activated = false;
} else if (int(convertedDataFromArduino) >= 11 && (sound2activated == false)) {
player2.loop();
println("growl");
sound2activated = true;
soundactivated = false;
}
//loop();
}
}