im trying to read a string from serial so i can change the value of an variable. right now my serial is only setup to read char which works fine untill i need to change a variable that hold a string of numbers. for instance if,
var=10000
and i want to change it to something else that i cant hardcode into arduinos code then i need to be able to read a string from serial. ive been reading posts and a lot of them talk about character arrays which i dont know anything about. how can i read a string and char from serial. i want to make it like below,
if (Serial.available()) {
char mode = Serial.read();
if (mode == 's') {
while(Serial.available() > 0)
///READ STRING OF NUMBERS
}
then
var=(stringofnumbers);
what the most simple way to read an undetermined length string of number and store then in a variable?
im trying to nest these if statements together but when i type "test 1" it just keeps repeating working 1 in the console. if i type test 2 it works fine, what am i doing wrong here?
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
if (strcmp(receivedChars, "test 2") == 0) {
Serial.println("working 2");
}
newData = false;
} else
if (strcmp(receivedChars, "test 1") == 0) {
Serial.println("working 1");
}
newData = false;
}
TolpuddleSartre:
Because the strings remain equal, because you're not resetting or clearing the received string?
im not sure what you mean. how do i clear a string. its weird because test 2 works just fine but test 1 just keeps printing? the top half of this code works untill test 1 which just keeps repeating. i though newdata = false; was suppose to take care of that?
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
if (strcmp(receivedChars, "test 2") == 0) {
Serial.println("working 2");
}
newData = false;
}
if (strcmp(receivedChars, "test 1") == 0) {
Serial.println("working 1");
}
newData = false;
}