I am wondering why my code below gets the correct values as it loops (2,5 and 5) but once I place them in the array it comes out 157?
char results[2];
char resultVals[2];
int i = 0;
int x = 0;
void setup() {
SerialUSB.begin();
strip.begin();
}
void loop() {
while (SerialUSB.available())
{
char recieved = SerialUSB.read();
if (recieved == '\n')
{
SerialUSB.println("found new line");
if (x == 2) {
//Finished captureing ALL 3 values (xxx xxx xxx)
x = 0;
i = 0;
memset(results, 0, sizeof(results));
SerialUSB.println("end");
} else {
SerialUSB.print("capture the 3 values: ");
SerialUSB.print(results[0] + results[1] + results[2]);
SerialUSB.println("");
//capture the value
resultVals[x] = results[0] + results[1] + results[2];
x++;
i = 0;
}
} else {
//Not the full XXX yet so keep looping.
SerialUSB.print("looping: ");
SerialUSB.print(recieved);
SerialUSB.println("");
results[i] += recieved;
i++;
}
}
SerialUSB.delay(10);
}
The serial output is this:
looping: 2
looping: 5
looping: 5
found new line
capture the 3 values: 157
looping: 2
looping: 5
looping: 5
found new line
capture the 3 values: 313
looping: 2
looping: 5
looping: 5
found new line
end
What is the reason why its not taking in 255 and instead putting 157?
What is that line supposed to do? Are you hoping to cram all 3 characters into one character? Not gonna happen. I told you how to print it. Do you need it as a number? Try atoi.