Issues whith serial dataincome

when i press button, in serial incomes aa string that activates bool, and if it = true, then i can declare speed of the motor, but code works onlu a few times and then nothing.

if (Serial.available() > 0) {
    String s = Serial.readStringUntil('\n');
    if (s == "aa") {
      initial = !initial;
    }
    if(initial == true){
      jj = Serial.parseInt();
      if(jj >0 && jj <=255){
        analogWrite(3, jj);
      }
    } else if(!initial){
      digitalWrite(3, LOW);
    }
  }

thanks so far

ps except this code there are demanded variables, away from it, but here i thought no need to write full code

I moved your topic to an appropriate forum category @robot0889.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Please post your full sketch so that the problem can be seen in context

Which Arduino board are you using ?

What button?

Where are these characters coming from?

What sequence is it supposed to respond to? Post the characters that you expect to read, and post enough of them so we get the idea of what you are looking for from the serial stream.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.