split strings(basic) from Arduino

edited May 2014 in Arduino

Hi, I am successfully able to send messages to processing from Arduino.. Here's what the serial output looks like:

Image and video hosting by TinyPic

But I am having problems specifically 'ArrayOutOfBoundsException' at line 10 in processing.. And I really cannot figure out why. It's weird because when I print out a1[0] , it gives me only the X value-> X3=110.3(whatever value) etc.. a1[1] should give me the Y value no?

void draw() {
  while (port.available () > 0) {
    serial = port.readStringUntil('\n');
    if (serial != null) {

      String[] a1 = split(serial, ' ');
      String[] a2 = split(a1[0], ':');

      println(a1[1]);    **<---------- THIS IS WHERE I AM GETTING THE OUT OF BOUNDS EXCEPTIONS. CANT FIGURE OUT    WHY
      **
      float foo = Float.parseFloat(a2[1]);

      background(0);
      rect(width/2, height, 100, (int)foo/2); 
      if (foo > 105.0) {
        if (!player1.isPlaying()) {
          player1.play(); 
          // break;
          player1.rewind();
        }
      }
    }
  }
}

Answers

  • line 9 : do you mean a2[1] ?

    you can use println (a1.length);

    to check

Sign In or Register to comment.