Hi!
My question is about Serial and I wonna when i send a word or anything in Serial monitor it reads it.
I mean Serial reads that word without delay because when i use readString() method it reads that word with 1 second delay do you know a method that can fix it? if you know please say. here is my Code. my code is when i say Plus in Serial monitor led is On and when i say - it says off and turn off the led this is my code:`void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
digitalWrite(12,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0){ // when the Serial was available
if(Serial.readString() == "+"){ // when + has sent
Serial.println("OK On"); // turn on the led
digitalWrite(12,HIGH);
}
if(Serial.readString() == "-"){ // when - has sent
Serial.println("OK Off"); // turn off led
digitalWrite(12,LOW);
}
}else{
Serial.println(Serial.available());
}
Before you can use stncmp() you have to get your string into a zero terminated array of chars, also known as a C string (NOT a String with a capital S)
it is not clear to me what you mean by that.
You have to write more words to describe what you are typing into your computer to send as string and then more words to describe the behaviour of the code.
In any way your code has to determine in any way if the received character was the last character or not. (without using the mysterious "looks-into-the future-glas-sphere"-library ;-))))
This can be done by timeout (which you don't want) or by any special character that indicates "endofString"
How to do this is shown in the serial input basics
Note that the Serial Monitor provided with the IDE requires to type 'Enter' at the end of the line to send the text (and that might send as well additional characters (CR and/or LF) depending how you configured the pulldown menu for end of line). If you use a different terminal, you might be able to send characters as they are being typed and thus could react to ++ without hitting the 'Enter' key (CoolTerm allows for this for example)
When you enter a character or several characters into the Serial monitor nothing is sent to the Arduino until you press Return. When you do that the Serial monitor adds the characters defined in the Line ending dialogue to the characters sent. This can be a Newline (character 10), a Carriage Return (character 13), both of them or nothing at all
These characters can be detected in your code so that you know that the user has finished entering something
Additionally to receive a better and more detailed help you should post an example of what you want to enter
I will use the #-symbol to mark beginning and end of the characters to enter. This means only the characters between the leading and trailing "#" are the real input
Examples:
Do you want to enter #200# ?
Do you want to enter #200++# ?
Do you want to enter #30+40# ?