Multiple Serial Read value

Hey guys, I am not sure if I am posting the right place but hope you can help me out here.

My Project is going to output two values(frequency and amplitude) to my sensor. And I am using the Arduino Uno.

Here's my code:

const int XPin = 2;
const int YPin = 3;
char Select;

void setup() {
  pinMode(XPin, OUTPUT);
  pinMode(YPin, OUTPUT);
  analogWrite(XPin, 0);
  analogWrite(YPin, 0);
  
  Serial.begin(9600); 
  while(!Serial);
  
  Serial.println("Please select your function, Fre = f, Amp = a");
}

void loop() 
{
  
  if (Serial.available()){
   char Select = Serial.read();
   if(Select == 'f'){
   Serial.println("you select Frequency function");
   char Axis_fre = Serial.read();
   int fre = Serial.parseInt();
   write_fre(Axis_fre, fre);
  }
  
  if(Select == 'a'){
   Serial.println("you select Amp function");
   char Axis_amp = Serial.read();
   int amp = Serial.parseInt();
   write_amp(Axis_amp, amp);
   
}
return;
}
}

void write_fre(char Axis_fre, int fre)
{
   
if (Axis_fre == 't'){
  analogWrite(XPin, fre);
  Serial.print("x");
  Serial.print(" fre =");
  Serial.println(fre);
  return;
}


if (Axis_fre == 'g'){
  analogWrite(YPin, fre);
  Serial.print("y");
  Serial.print(" fre =");
  Serial.println(fre);
  return;
}
return;
}

void write_amp(char Axis_amp, int amp)
{
  
if (Axis_amp == 'w'){
  analogWrite(XPin, amp);
  Serial.print("x");
  Serial.print(" amp =");
  Serial.println(amp);
  return;
}

if (Axis_amp == 's'){
  analogWrite(YPin, amp);
  Serial.print("y");
  Serial.print(" amp =");
  Serial.println(amp);
  return;
}
return;
}

I only can choose my function f and a, there's nothing showed after that. Could you guys give me some suggestion?? Thanks a lot.

Macive

You have two copies of Select. One is global and the other is local to the body of one of your if() statments.

The type specifier (in this case char) is an instruction that means "I'd like to make a new variable of this type, please". You don't put it everywhere as you don't need multiple copies with similar names.

MorganS:
You have two copies of Select. One is global and the other is local to the body of one of your if() statments.

The type specifier (in this case char) is an instruction that means "I'd like to make a new variable of this type, please". You don't put it everywhere as you don't need multiple copies with similar names.

Hi MorganS,
Thanks for your reply, I delete the global char Select and it still failed, any suggestion??

I think my problem here is since the "char select" has been read, the Arduino can't read another char and my two values Fre and volt, if one has been read, the other can't be. So is there any solution for solving this problem? Since Arduino Uno can only read one serial port.

You deleted the wrong one.