Hi, so I’m doing a project with arduino and processing. The arduino code is okay, but my processing code for some reason isn’t working right. It used to display an image as well as run a sound but now it does neither of those things and I have no idea why. The code is as follows. I would be so so grateful if somebody could help me with this.
import controlP5.;
import processing.sound.;
SoundFile mySoundFile;
ControlP5 cp5;
import java.io.File;
import processing.opengl.;
PImage im;
boolean displayImage;
boolean var = true;
import processing.serial.;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
void setup()
{
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
size(500, 500);
cp5 = new ControlP5(this);
selectInput(“Select a file to process:”, “fileSelected”);
cp5.addButton(“onOff”).setValue(0)
.setPosition(10,10).setSize(200,19);
}
void fileSelected(File selection) {
println("User selected " + selection.getAbsolutePath());
im = loadImage(selection.getAbsolutePath());
}
public void onOff(int val){
displayImage = !displayImage;
}
void draw()
{
background(0);
if ( myPort.available() > 0) {
String inBuffer = myPort.readStringUntil(10);
if (inBuffer != null) {
if(inBuffer.indexOf(“h”)!=-1){
boolean var = false;
println(var);
}
}
if (im != null){
if(displayImage){
image(im, 0, 30);
if (var == false){
mySoundFile = new SoundFile(this, “Vocaroo 29 Jan 2021 17_28_57 CST 12e5cJxlGN7j.mp3”);
mySoundFile.play();
}
}
}
}
}
Like I said, it worked before and then just decided to stop. My port is ok, and I have the sound file and everything uploaded correctly. The libraries are also installed. I’m really confused at this point. Anything would help.