Hi
how can I print decimal numbers with decimal point in serial arduino like (1234.23)
I wroten this sketch but i cant write numbers with decimal point like 342.23
farsad:
Hi
how can I print decimal numbers with decimal point in serial arduino like (1234.23)
I wroten this sketch but i cant write numbers with decimal point like 342.23
void setup() {
Serial.begin(9600);
Serial.setTimeout(10);
}
void loop() {
char buffer[] = {' ',' ',' ',' ',' ',' ',' ',' ',' '}; // Receive up to 8 bytes
while (!Serial.available()); // Wait for characters
Serial.readBytesUntil('n', buffer, 8);
double incomingValue = atoi(buffer);
Serial.parseFloat();
Serial.print(incomingValue, DEC);
}
please guide me
Why are you looking for an 'n' in your input?
Why are you doing a .parseFloat() and throwing away the result?
I think what you want is more like:
void loop() {
while (!Serial.available()); // Wait for characters
double incomingValue = Serial.parseFloat();
Serial.print(incomingValue);
}