**Solved. Was using "0" and not '0'. **
Thank you Bob.
I'm working on a way to manipulate a 2 dimensions array from serial command on an arduino. Problem is I'm able to take the string, seperate certain characters to multuple variables, but I can't seem to make these variables integers where I can make use of them injecting them into their necessary position of the array. Then seem to not convert from accii? to integers.
int Bit8;
int Bit9;
int Bit10;
int Bit12;
int Bit13;
int Bit14;
int Bit15;
int Bit16;
String command;
Disregard the following voids as it's irrelevant to the issue.
void Setup()
void exportArray() {
void loop() {
if (Serial.available()) {
command = Serial.readStringUntil('\n');
command.trim();
if (command.equals("Print Array")) {
Serial.println("Exporting Array");
exportArray();
} else if (command.equals("Help")) {
Serial.println("Command Options");
Serial.println("Commands:");
Serial.println("Print Array");
Serial.println("Change *** *****");
} else if (command.startsWith("Change")){
Serial.println("Changing");
Bit8 = command[7];
Bit9 = command[8];
Bit10 = command[9];
Bit12 = command[11];
Bit13 = command[12];
Bit14 = command[13];
Bit15 = command[14];
Bit16 = command[15];
// Bit8 = atoi(Bit8);
// Bit9 = atoi(Bit9);
// Bit10 = atoi(Bit10);
// Bit12 = atoi(Bit12);
// Bit13 = atoi(Bit13);
// Bit14 = atoi(Bit14);
// Bit15 = atoi(Bit15);
// Bit16 = atoi(Bit16);
Serial.print(Bit8);
Serial.print(Bit9);
Serial.print(Bit10);
Serial.print(" ");
Serial.print(Bit12);
Serial.print(Bit13);
Serial.print(Bit14);
Serial.print(Bit15);
Serial.println(Bit16);
} else {
Serial.println("bad command");
}
Serial.print("Command: ");
Serial.println(command);
}
}
If I enter Change 123 12345 into the serial monitor this is what gets returned.
16:45:20.088 -> Changing
16:45:20.088 -> 505132 505152530
16:45:20.088 -> Command: Change 123 12345
If I enable the Bit* = atoi(Bit*); in the code this is what's returned.
16:47:16.211 -> Changing
16:47:16.211 -> 000 00000
16:47:16.211 -> Command: Change 123 12345
I've dug through other ideas and saw one instance where someone was able to do...
Bit8 = ((Bit8) - "0");
But I endup with "invalid operands of types 'int' and 'const char [2]' to binary 'operator-'" when trying to do a compile.
What am I missing or doing wrong here.