title: Parsing serial string data into an array (VVVV to Arduino)
body: <p>I'm currently working on an arduino project at University. Basically what I am trying to do is send a string of data from VVVV to arduino, however I need to parse the data into an array and I have absolutely no idea how to do this! </p>
  
  <p>The string being sent from VVVV is something like this; U,c,R,|,W,H,P and I need each of those values to be written to a specific servo each time, so value 1 need to go to servo 1, and so on. </p>
  
  <p>Here is my code at the moment, I realize its coded pretty badly, and I do intend to make to make it more efficient when I have worked out how to parse the data. </p>
  
  <pre><code>#include &lt;Servo.h&gt;
  Servo servo1;
  Servo servo2;
  Servo servo3;
  Servo servo4;
  
  char array1[4] = { '0', '0', '0', '0'}; //array for midi variables
  
  void setup()
  {
   // begin the serial communication
   Serial.begin(9600);
  
   servo1.attach(2);
   servo2.attach(3);
   servo3.attach(4);
   servo4.attach(5);
  
  }
  
  void loop(){
    while (Serial.available() == 0)  {
      array1[0] = 0;
      array1[1] = 0;
      array1[2] = 0;
      array1[3] = 0;
    }
  
  {
  
  
   // check if data has been sent from the computer
   if (Serial.available() &gt;= 4) {
      for ( int i = 0; i &lt; 4; i++)
      array1[i] = Serial.read();
  
  
    }
  
  
     Serial.print(array1[0]);
     Serial.print(array1[1]);
     Serial.print(array1[2]);
     Serial.print(array1[3]);
  
  
  
     servo1.write(array1[0]);
     servo2.write(array1[1]);
     servo3.write(array1[2]);
     servo4.write(array1[3]);
  
  
  }
  }
  </code></pre>
  
  <p>Edit - I should probably mention that I'm eventually looking to use 7 servos, but for the moment I'm just using 4 in my circuit. Also, when I upload this patch and enable VVVV, the arduino just disconnects. </p>