1

I am trying to keep the program within a loop until the user inputs "ok" on the Bluefruit Connect App. I use the readString() function on the bluetooth object (ble) to read from it. Before this loop, my String command variable is initialized to be empty. Here is my code:

while(!command.equalsIgnoreCase("ok"))
{
  while(ble.available())
    command = ble.readString()
}

I have confirmed that I can receive data as I can output the command variable to the Serial monitor. Why does the condition for this loop always return true (i.e. why is the String command variable never equal to the string literal "ok", while ignoring case)?

4
  • 1
    output the length of the command variable to serial monitor ... it may not be what you expect ... always do that when you're debugging code – jsotola Mar 5 at 18:38
  • @jsotola Wow you are right. When I send the string "ok" it says the length is 3. Is that the newline character being sent with it, or something else? How would I go about removing that extra character in the string? – Cem Adatepe Mar 5 at 19:21
  • this may help ... majenko.co.uk/blog/reading-serial-arduino – jsotola Mar 5 at 19:27
  • @jsotola It's working now! Thank you so much! – Cem Adatepe Mar 5 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.