How can I use delimiter/split serial input in a loop function? I want to use each word from the input and check a database, to check availability.
#include SoftwareSerial.h>
#define MAX_WORD_LENGTH 15
char messageArray[5][MAX_WORD_LENGTH + 1];
SoftwareSerial BT(10, 11);
String command = "";
char message[] = "";
void setup() {
BT.begin(9600);
Serial.begin(9600);
while (BT.available()) {
delay(10);
char c = BT.read();
command += c;
}
if (command.length() > 0) {
Serial.println(command);
char message[] = {command};
for (int i = 0; i < 5; i++) {
// you can 'reset' the array by writing a null to the first element of each
messageArray[i][0] = '\0';
}
sscanf(message, "%s %s %s %s %s", messageArray[0], messageArray[1], messageArray[2], messageArray[3], messageArray[4]);
for (int i = 0; i < 5; i++) {
Serial.println(messageArray[i]);
delay(1000);
}
}
}
void loop() {
for (int i = 0; i < 5; i++) {
// you can 'reset' the array by writing a null to the first element of each
messageArray[i][0] = NULL;
}
command = "";
}