Arduino - processing: serial data to toggle mp3 file in minim

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.

L
L
L
L
in the Quiet if statement
L
L
L
L

1 Like