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 ?
b707
October 28, 2023, 9:58am
3
Sophisticated_pingo:
if(input == naprej){
Sophisticated_pingo:
if(input == nazaj){
Where the variables naprej and nazaj are defined?
1 Like
oopsie i was translating and it seems i missed a few lines
Did you forget the forwardj variable ?
PaulRB
October 28, 2023, 10:05am
10
Will the commands every be more than a single character?
b707
October 28, 2023, 10:05am
11
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
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
When you use readString() what you have got set as the line ending is included in the String that it returns
b707
October 28, 2023, 10:14am
17
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
2112
October 28, 2023, 11:32am
19
What is this line doing? Compare it to some examples.
2112:
What is this line doing?
It is waiting for at least a single byte of Serial data to become available