For starters, you probably should fix those import statements to be:
import processing.serial.*;
import ddf.minim.*;
It may have nothing to do with your problem, but neither processing.serial or ddf.minim are things you can import, they’re just package names.
So it’s printing out the values correctly that your Arduino board is sending? Have you tried throwing in a few println statements to see whether it’s getting into the if blocks? Do you have a playable file called ‘groove.mp3’?
P.S.
You can also the ‘</>’ button in the post editor to have code shown properly, or place the code in between two lines of triple backticks ( ``` ).
Yes, there is a file playing called ‘groove.mp3’ It plays within the else loop. The console prints ‘status: Q’ or ‘status: L’ depending on the input from the Arduino.
I have tried println to the console from within the if block: if (val.equals(“L”)) {… and nothing prints out.
Hi again.
Thank you very much for this.
I have tested your processing code example and getting this error message in the console:
==== JavaSound Minim Error ====
==== java.io.FileNotFoundException: data/groove.mp3
=== Minim Error ===
=== Couldn't load the file data/groove.mp3
try connect to /dev/cu.usbmodem1421
we expect keyboard [l] or [q] or USB line 'L' or 'Q'
Q
Error, disabling serialEvent() for /dev/cu.usbmodem1421
null
This the Processing code I’m using:
import processing.serial.*;
import ddf.minim.*;
//import processing.video.*;
Minim minim;
AudioPlayer player;
Serial myPort;
String val = null;
void setup() {
minim = new Minim(this);
size(640, 480);
String portName = Serial.list()[2];
myPort = new Serial(this, portName, 9600);
myPort.clear();
myPort.bufferUntil('\n');
player = minim.loadFile("data/groove.mp3");
}
void serialEvent (Serial myPort) {
while (myPort.available() > 0) {
val=myPort.readStringUntil('\n');
if (val != null) {
val = val.trim(); // let's remove whitespace characters
if (val.equals("L")) {
if (player.isPlaying() == true) {
player.loop();
println("in the Loud if statement");
}
}
//} else {
if (player.isPlaying() == false) {
player.pause();
println("in the Quiet if statement");
//println(val);
}
}
}
}
void draw() {
background(0);
println(val);
}
With this Arduino code (board Leonardo):
// Define hardware connections
#define PIN_GATE_IN 2
#define IRQ_GATE_IN 0
#define PIN_LED_OUT 13
#define PIN_ANALOG_IN A0
// soundISR()
// This function is installed as an interrupt service routine for the pin
// change interrupt. When digital input 2 changes state, this routine
// is called.
// It queries the state of that pin, and sets the onboard LED to reflect that
// pin's state.
void soundISR()
{
int pin_val;
pin_val = digitalRead(PIN_GATE_IN);
digitalWrite(PIN_LED_OUT, pin_val);
}
void setup()
{
Serial.begin(9600);
// Configure LED pin as output
pinMode(PIN_LED_OUT, OUTPUT);
// configure input to interrupt
pinMode(PIN_GATE_IN, INPUT);
attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);
// Display status
Serial.println("Initialized");
}
void loop()
{
int value;
// Check the envelope input
value = analogRead(PIN_ANALOG_IN);
// Convert envelope value into a message
//Serial.print("Status:");
if(value <= 10)
{
Serial.println("Q");
}
else
{
Serial.println("L");
}
// pause for 0.5 second
delay(500);
}
is printing ‘Q’ and ‘L’ depending on the Arduino input, however the printLn (“in the Quiet if statement”) only gets through rarely.
i modified your serial event code until it worked here, so i will not
again work with yours.
first, the minim error ?
i expect that files are under data/…
and processing can read from sketchpath and datapath,
but i recommend to use absolute path,
you could however change to
String song = "groove.mp3"; //______________________ select song
other thing is that i recommended with my code example to
separate the song logic from the serial logic,
in my example then also can start from keyboard,
using the same loop/pause logic