 int j = 0;
 int k = 0;
 int l = 0;
+int duration, pause_t;
 char data_string[6][6];
-int data[50];
+char data[50];
 int indices[6];
+String test;
+String f_new_s, amp1_s, amp2_s, duration_s, pause_t_s;
 
-bool received_data;
+
+bool received_data = false;
 
 
 // table of data send by Matlab through the first arduino

  Wire.begin(1);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(57600);           // start serial for output
}

void loop()
{
  delay(100);
    if(received_data){
      
  f_new = atoi(data_string[0]);
  Serial.println(f_new);
  amp1 = atof(data_string[2]);
  Timer1.start();
  delayMicroseconds(atoi(data_string[4]));
  Timer1.stop();
  delayMicroseconds(atoi(data_string[5]));
  f_new = atoi(data_string[1]);
  amp2 = atof(data_string[3]);
  Timer2.start();
  delayMicroseconds(atoi(data_string[4]));
  Timer2.stop();
  received_data =  false;}
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
  data[j] = x;
  j++;
  if(j > 2 && data[j] == 110 & data[j-1] == 92){
    indices[k] = j;
    Serial.println(j);
    k++;
    if(k>0){
    for(l = indices[k-1]; l = indices[k]; l++){
      data_string[k][l] = data[l];}
  }}
    if(j > 2 && data[j] == 116 & data[j-1] == 92 ){
  received_data = true;
  Serial.println("Valid Test");
  j = 0;}

}

double amp2;   // amplitude of the second stimulus
int wave;   // waveform
int x;

int f_new;
int num_samples = 100000;
