Triggering an audio file to play in my processing sketch. Using Firmata

Hi there,

I am fairly new to Arduino and processing and am at a bit of a standstill. I have the standard firmata loaded onto my Arduino with a light sensor on my breadboard hooked up to the ‘0’ analog output. This circuit works with the ‘arduino_input’ example and the circles in the sketch shrink when their is low light and enlarge when their is high light.

What I am trying to do is have the audio file load when the light sensor picks up a high amount of light. I have a processing sketch that plays an audio file from its data folder when it runs. But I cannot figure out how to trigger that command when there is a high light source.

This is my attempt at adding parts of the arduino example code into my processing sketch.

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

import ddf.minim.*;

AudioPlayer player;

Minim minim;

void setup()
{
  size(500, 500, P2D);
  background(0);
  
  // Prints out the available serial ports.
  println(Arduino.list());
  
  // Set the Arduino digital pins as inputs.
  for (int i = 0; i <= 13; i++)
    arduino.pinMode(i, Arduino.INPUT);
  
  arduino = new Arduino(this, "/dev/tty.usbmodemfd131", 57600);
  
    for (int i = 0; i <= 13; i++) {
    if (arduino.digitalRead(i) == Arduino.HIGH)
  
  minim = new Minim(this);
  
  player = minim.loadFile("JM01.mp3", 2048);

  player.play();

}

void draw(){
  
}


void stop()
{
  player.close();
  minim.stop();
  
  super.stop();
}

I have tried many different variations of this but haven’t had any luck, I’m hoping it is something not too major that I am doing wrong. Any help or ideas would be greatly appreciated. Thanks.

I have the standard firmata loaded onto my Arduino with a light sensor on my breadboard hooked up to the '0' analog output.

Analog pin 0 is not an output. By loading firmata on the Arduino, you've given it a lobotomy. It does NOT send data to Processing on its own. It only responds to requests for data.

void draw(){
  
}

So, you never ask the Arduino about the pin, so Processing does nothing. Not surprising.