No help needed anymore

Hello, I have a few problems.

  1. When I start the code and open the serial monitor, the serial prints don't go on, the serial monitor is asking over and over again the same question, and whether I type yes(oui) or non(no), nothing changes.

  2. In the getInclinometre part, while turning the potentiometer, there will be multiple values showing up. While they are showing up, how do I make the user press enter to select one of them when they are satisfied with the value showing up? Is the
    while (Serial.available() == 0 || Serial.available() == 1) {
    }{
    return Serial.parseFloat();
    }
    part good?

Here's my code:


int ANALOGUE_RESISTOR_VARIABLE = A0; //La broche analogique A0 pour le capteur d'angle rotatif
int VALEUR_RESISTOR_VARIABLE = 1023.0;
int ADC_REF = 5; //Tension de référence de l'ADC est de 5v
int VALEUR_TOTALE_ANGLE = 270.0; //Valeur totale de l'angle de rotation est de 270 degrés
int DEL_ROUGE = 9; //Broche DEL rouge
int DEL_BLEUE = 4; //Broche DEL bleue
int LASER = 10; //Broche Laser
int distance  = "";
int heightinclino = "";
String reponse = "";
String reponse2 = "";
int distancehaut = "";
double hauteur;
double degree;



void setup()

{
  //Démarrer la connexion série
  Serial.begin(9600);

  //Données des outputs
  pinMode (DEL_ROUGE, OUTPUT);
  pinMode (DEL_BLEUE, OUTPUT);
  pinMode (LASER, OUTPUT);

  Serial.print("INCLINOMÈTRE");
}

int CalculsDegres()
{
  //Lecture de la valeur brute de la broche analogique du résistor variable
  analogRead(ANALOGUE_RESISTOR_VARIABLE);

  //Conversion de la lecture du capteur en degrés et renvoie de cette valeur
  double degree = (float)analogRead(ANALOGUE_RESISTOR_VARIABLE) * (VALEUR_TOTALE_ANGLE / VALEUR_RESISTOR_VARIABLE);
  return degree;
}

int getInclinometre() {

  //Allumer le laser
  digitalWrite (LASER, HIGH);


  //Lecture de la valeur du capteur d'angle de rotation en degrés
  double degree = CalculsDegres();

  //Carte pour les limites de valeurs et l'horizon
  degree = map(analogRead(ANALOGUE_RESISTOR_VARIABLE), 0, 1023, -135, 135);

  //Écriture des données
  if (degree > 0) {
    Serial.print("Angle d'élévation: ");
    Serial.println(degree);
    digitalWrite(DEL_BLEUE, HIGH);
    digitalWrite(DEL_ROUGE, LOW);
  }
  else if (degree < 0) {
    Serial.print("Angle de dépression: ");
    Serial.println(degree);
    digitalWrite(DEL_ROUGE, HIGH);
    digitalWrite(DEL_BLEUE, LOW);
  }
  else {
    Serial.print("HORIZON = ");
    Serial.println(degree);
    digitalWrite(DEL_ROUGE, LOW);
    digitalWrite(DEL_BLEUE, LOW);
  }

  while (Serial.available() == 0 || Serial.available() == 1) {
  }{
    return Serial.parseFloat();
  }


  //Délai entre les lectures
  delay(100);
}

int getHauteur()

{ double haut =  tan(degree) * distance;
  double hauteur = haut + distancehaut;
}

void loop() {



  {

    Serial.println("Souhaitez-vous aussi trouver la hauteur du sujet?");
    while (Serial.available() == 0)   {}
    reponse = Serial.readString(); //Reading the Input string from Serial port.

    if (reponse == "Oui") {
      Serial.println("Insérez la distance entre l'inclinomètre et le sujet.");
      while (Serial.available() == 0)   {}
      distance = Serial.parseInt(); //Reading the Input string from Serial port.

      Serial.println("Angle d'élévation (É) ou de dépression (D)?");
      while (Serial.available() == 0)   {}
      reponse2 = Serial.readString(); //Reading the Input string from Serial port.

      if (reponse2 == "É") {
        Serial.println("Insérez la distance entre l'inclinomètre et le sol.");
        while (Serial.available() == 0)   {}
        distancehaut = Serial.parseInt(); //Reading the Input string from Serial port.

        Serial.println("Calculez l'angle.");
        int angle = getInclinometre();

        Serial.println("Voici la hauteur de votre sujet = ");
        double hauteur = getHauteur();
        Serial.println(hauteur);
      }

      if (reponse2 == "D") {
        Serial.println("Insérez la distance entre l'inclinomètre et le haut de votre sujet.");
        while (Serial.available() == 0)   {}
        distancehaut = Serial.parseInt(); //Reading the Input string from Serial port.

        Serial.println("Calculez l'angle.");
        int angle = getInclinometre();

        Serial.println("Voici la hauteur de votre sujet = ");
        double hauteur = getHauteur();
        Serial.println(hauteur);

      }

    }

    if (reponse == "Non") {
      int inclinometre = inclinometre;
    }

  }



}



Hello midnight9618
Check this line.

Why do use a WHILE instruction instead an IF instruction?
A secondary WHILE loop is not need, the Arduino loop() call is doing this all the time.
Have a nice day and enjoy coding in C++.

This line will also read in whatever line ending you have Serial Monitor set to - Such as newline or CR or both. If you have that set, "Oui" will not equal "Oui\n"

This shows the issue:

String response = "";

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("ready");
}

void loop() {
  while (Serial.available() == 0 ) {
    
  }
  response = Serial.readString();

  Serial.print("response = '");
  Serial.print(response);
  Serial.println('\'');
}

@midnight9618 has indicating they will no longer be participating in this thread. Thread locked.