Go Down

Topic: split string by delimiters (Read 123455 times) previous topic - next topic


There is now a SafeString library available from the Arduino Library manager which includes a number of tokenizer methods and a simple effective example of parsing user input for keywords without blocking the rest of the sketch  from running

SafeStrings do not cause heap fragementation and never cause the sketch to reboot and have detail debugging available.

Code: [Select]
void loop() {
  // read from Serial, returns true if at least one character was added to SafeString input

  if (input.nextToken(token, delimiters)) { // process at most one token per loop does not return tokens longer than input.capacity()

    if (token == startCmdStr) {
      running = true;  Serial.print(F("start at ")); Serial.println(loopCounter);

    } else if (token == stopCmdStr) {
      running = false; Serial.print(F("stop at ")); Serial.println(loopCounter);

    } else if (token == resetCmdStr) {
      loopCounter = 0; Serial.print(F("reset Counter:")); Serial.println(loopCounter);

    }// else  // not a valid cmd ignore

  // rest of code here is executed while the user typing in commands
  if (running) {
    if ((loopCounter % 100000) == 0) {
      Serial.print(F("Counter:")); Serial.println(loopCounter);


As you might have gathered I wasn't entirely serious about programming an Arduino in MUMPS.
I learned a language called FROG ... way back in high school ... I think DOS was on version 2 or 3 back then ... 1986-ish
Mike Sims

Go Up