Dear all,
I would like to read from serial a string (a character followed by a X digits number) as this one for example: c123456.
The number can be between 2 or 6 digit.
void loop() {
...
if (Serial.available() > 0) {
if(Serial.read() == 'c')
{
int output = intParse(6);
Serial.print(output);
}
int intParse(int length)
{
char BUFFER[length];
delay(5);
for(int i = 0; i < length; i++)
{
BUFFER[i] = Serial.read();
}
BUFFER[length] = '\0';
return atoi(BUFFER);
}
This works with numbers with digit < 5 otherwise it will truncate.
Am I missing something from the atoi function?
Thank you for your support,
dk