How do i make it so the program doesnt just spit out the else option every time

every time it gives me the Not right option

String forward = "f";
String back = "b";
String left = "l";
String right = "r";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
    Serial.println("drive");

  while (Serial.available() == 0) {
  }
  String input = Serial.readString();
  
  if(input == forwardj){
   //code
      Serial.println("forward");
      }
      else
      
   if(input == back){
   //code
  Serial.println("back");
  }
      else
      
    if(input == left){
      
   //code
  Serial.println("left");
  }
      else

    if(input == right){
      //code
   Serial.println("right");
   }
       else
      Serial.println("not right");

   
   

}

i am quite new so please don't overheat my braicells

Welcome to the forum

What have you got Line ending set to in the Serial monitor ?

Where the variables naprej and nazaj are defined?

1 Like

oopsie i was translating and it seems i missed a few lines

fixed it

NL- the second option

Did you forget the forwardj variable ?

Set it to No Line ending

lol

Will the commands every be more than a single character?

About the forum rules: please do not edit the code in place. Every time you fixed errors in the code - insert it again as a new message.

A common way to prevent endless printing is to remember the last input that was received and compare it with new input. Only if they differ, do things; else simply do nothing.

1 Like

oka sry i just got here

these are very basic one letter ones, but when i translate it back to my language or want a left-forward turn it would be nice to have a multiple letter option

How does this fix it?

When you use readString() what you have got set as the line ending is included in the String that it returns

If you change the mind to use one-letter command, the code can be less complicated.

nah.
i have been doing this for three days and haven't even started o the code.
i'm fine

What is this line doing? Compare it to some examples.

It is waiting for at least a single byte of Serial data to become available