Can't get any sound out of my values.

edited January 2014 in Arduino

Hee! can someone help me? I'm new with processing but I'm trying to couple my arduino with processing to create a sound when a pin is touched. I managed to get values out of my capacitive touch sensor but I don't manage to get sound out of it. Is there anyone who can help me?

import ddf.minim.*;
import processing.serial.*;

// declariatie van globale variabelen
Minim minim;
AudioSample sound1;
Serial myPort;
//String aReadout = "pin 1 was just touched"; 


// initializatie van het programma
void setup() {
  size(100, 100);
  background(0);
  frameRate(60); 

  minim = new Minim(this);
  sound1 = minim.loadSample( "geluid.wav",512);   // lees de soundfile in de buffer

  println(Serial.list()); // toon alle seriele poorten op de machine
  myPort = new Serial(this, Serial.list()[4], 9600);  // open een nieuwe seriele poort
  myPort.bufferUntil('\n');
}




// deze functie wordt automatisch aangeroepen als er seriele data ontvangen wordt

void serialEvent(Serial myPort) 
{ 
  String inString = myPort.readString();
  println(inString);
  if (inString != null) 
  {
    inString = trim(inString);  // verwijder spaties en tabs rond de string

    int[] values = int(split(inString, ",")); // splits de string in blokken op basis van de comma en zet om naar integers

    /* HIER WIL LEZEN EN ANALYSEREN WAT DE ARDUINO JE HEEFT TOEGESTUURD. 
       HET RESULTAAT ZIN IN DE ARRAY values
       als het goed is zit er in values[0] de integerwaarde voor aan of uit en in values[1] het nummer van de pin
    */


    if(int(0) == 1)   // button wordt aangeraakt
    {
        // welke button?
        if(int(1) == 8)   // is het button 8?
        {
          println("button 8 wordt ingedrukt");
          sound1.trigger();//play sound
        }
        else if(int(1) == 9)
        {
          // etc.

        }
    }
    else if(int(0) == 0)
    {
        // welke button?
        if(int(1) == 8)   // is het button 8?
        {
          println("button 8 wordt losgelaten");
        }
        else if(int(1) == 9)
        {
          // etc.

        }
    }

  }
}
// EIND VAN DE SERIELE EVENT AFHANDELING

void draw() 
{


}   

Answers

  • edited January 2014

    Hello again. I can't help ya w/ the Minim as I've stated before. But again:
    That int() isn't an array, but a function to convert values to primitive data-type int:

    http://processing.org/reference/intconvert_.html

    Of course, it subverts the Java rule of not naming anything w/ a reserved keyword.
    It appears to get away w/ it b/c Processing's pre-compiler transforms that to PApplet.parseInt() before compiling it as Java! B-)

Sign In or Register to comment.