Two Serial inputs

Hi guys I have a question regarding the serial input.

I have an analog input of an Hall sensor. And now I want to specify the sampling frequency and the timespan of the recording.
I managed to get the right outputs when I implemented one of the variables (time, frequency) already in the code.

But I want to be able to change the frequency and timespan via serial comands.

I though it would work if I had just two seperate commands with ("Serial.parseFloat()"). But it didnt gave me any outputs.

[code]
double volt; //output variable which is current voltage 
int sensor; //variable to hold voltage sensor value
double x = (5.0/1023.0); ////converting sensor value to voltage 
double freq = 0; //chosen frequency for data acquisition
double interval; //interval between two samples in micros
int rectime = 0; //time span for recordings
uint32_t starttime = 0;
uint32_t endtime;
uint32_t lastMicros = 0;



void setup() 
{
  pinMode(A0,INPUT);//sensor connected to analog 0
  pinMode(13,OUTPUT); 
  digitalWrite(13, HIGH); //Convert digitaloutput pin for using it as power supply
  analogReference(DEFAULT);
  Serial.begin(230400);
}

void loop() 
{
  inputFreq();     //first input read for frequency
  inputTime();     //second input read for Timespan 
  recdata();
}

void inputFreq()
{
  if (Serial.available() > 0)
  {
      //reads value for sampling frequency
      freq = Serial.parseFloat();  
      interval = (1/freq) * 1000000;
  }
}

void inputTime()
{
  if (Serial.available() > 0 && freq > 0)
  {
      //reads value for timespan
      rectime = Serial.parseFloat();  
  }
}

void recdata()
{
  if (freq > 0 && rectime > 0)
  {
   starttime = millis();
   endtime = starttime;

   while( endtime-starttime < rectime)
   {
      if (micros() - lastMicros > interval) 
      {
        lastMicros = micros(); 
      
        sensor = analogRead(A0); //analog reading sensor values
        volt = sensor * x;
        
        Serial.println(volt, 3); //print voltage with 3 significant figures
      }
      endtime = millis();
   }
  } 
}

[/code]

Also I would be happy over suggestions for my code. I am a bit new to programming.

Cheers

Whether you get inputFreq or inputTime is a flip of a (very fast spinning) coin.

You need to tell in advance which one you're sending.

Here is example code from the serial input basics tutorial showing how to receive your 2 values from serial monitor. The code uses a mix of code from example #2 (input with end marker) and example #5 (parsing variables).

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

unsigned long time;
float frequency;

void setup()
{
   Serial.begin(115200);
   Serial.println("Enter time and frequency delimited with comma.");  
   Serial.println("Ex. 10020,102.56\n");
}

void loop()
{
   recvWithEndMarker();
   if (newData == true)
   {
      parseData() ;
      showParsedData();
   }
}

void recvWithEndMarker()
{
   static byte ndx = 0;
   char endMarker = '\n';
   char rc;

   while (Serial.available() > 0 && newData == false)
   {
      rc = Serial.read();

      if (rc != endMarker)
      {
         receivedChars[ndx] = rc;
         ndx++;
         if (ndx >= numChars)
         {
            ndx = numChars - 1;
         }
      }
      else
      {
         receivedChars[ndx] = '\0'; // terminate the string
         ndx = 0;
         newData = true;
      }
   }
}

void parseData()        // split the data into its parts
{

   char * strtokIndx; // this is used by strtok() as an index

   strtokIndx = strtok(receivedChars, ",");     // get the first part - the string
   time = atoi(strtokIndx); // copy it to messageFromPC

   strtokIndx = strtok(NULL, ",");
   frequency = atof(strtokIndx);     // convert this part to a float
}

//============

void showParsedData()
{
   Serial.print("Time ");
   Serial.print(time);
   Serial.print("   Frequency ");
   Serial.println(frequency);
   newData = false;
}
Enter time and frequency delimited with comma.
Ex. 10020,102.56

Time 1234   Frequency 60.32
Time 10025   Frequency 1234.56