 double amp2;   // amplitude of the second stimulus
 int wave;   // waveform
 int x;
-int pause_t = 0;
 
 int f_new;
 int num_samples = 100000;

int j = 0;
int k = 0;
int l = 0;
char data_string[6][6];
int data[50];
int indices[6];

bool received_data;


// 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){
   Serial.println("So weit, so gut");
   for(i=0;i<50;i++){
   test += data[i];}
  // Serial.print(test);
   f_new_s = test.substring(1,indices[0]);
   f_new = f_new_s.toInt();
  amp1_s = test.substring(indices[0]+1,indices[1]);
  amp1 = amp1_s.toFloat();
  amp2_s = test.substring(indices[1]+1, indices[2]);
  amp2 = amp2_s.toFloat();
  duration_s = test.substring(indices[2]+1,indices[3]);
  duration = duration_s.toInt();
  pause_t_s = test.substring(indices[3]+1,indices[4]);
  pause_t =  pause_t_s.toInt();
  Timer1.start();
  delayMicroseconds(duration);
  Timer1.stop();
  delayMicroseconds(pause_t);
  f_new = atoi(data_string[1]);
  amp2 = atof(data_string[3]);
  Timer2.start();
  delayMicroseconds(duration);
  Timer2.stop();
  received_data =  false;
  j = 0;
}
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  j++;
  data[j] = Wire.read();    // receive byte as a char
 
  if(data[j] == 'n'){
    indices[k] = j-2;
    k++;
    if(k == 6){
    received_data = true;
  }}
  


}

