import processing.serial.*;
import processing.sound.*;
SoundFile file;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
//String antwoord = "A";
void setup()
{
size(300,300);
// I know that the first port in the serial list on my mac
// is Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
}
void draw()
{
if ( myPort.available() > 0)
{ // If data is available,
val = trim( myPort.readStringUntil(ENTER) );
// read it and store it in val
}
//println(val); //print it out in the console
if ("A".equals(val) == true && file.isPlaying() == false) {
file = new SoundFile(this,"Promise.mp3");
file.play();
file.amp(0.2);}
else{
ellipse(40,40,40,40);
}
}
This is my code, but i get a nullpointer exception at this line:
if ("A".equals(val) == true && file.isPlaying() == false) {
I just want to let the file below it play, when it isn’t already playing.