How to use strtod to convert a Serial.Read() data?
basically used visual studio send string data "1.11" testing purposes.
how make use of strtod convert double , show on serial monitor show
is transferred , converted.
#include <studio.h>
#include <stdlib.h>
int ledpin = a13;
char x[30];
char **ptr;
double h;
void setup()
{
pinmode(ledpin, output);
serial.begin(56700);
}
void loop()
{
if(serial.available())
{
x[30] = serial.read();
serial.println(x);
h = strtod(x,ptr);
if (h == 1.1)
{
digitalwrite(ledpin,high);
delay(1000);
}
else
if( h == 5.1)
{
digitalwrite(ledpin,low);
delay(1000);
}
}
}
how make use of strtod convert double , show on serial monitor show
is transferred , converted.
#include <studio.h>
#include <stdlib.h>
int ledpin = a13;
char x[30];
char **ptr;
double h;
void setup()
{
pinmode(ledpin, output);
serial.begin(56700);
}
void loop()
{
if(serial.available())
{
x[30] = serial.read();
serial.println(x);
h = strtod(x,ptr);
if (h == 1.1)
{
digitalwrite(ledpin,high);
delay(1000);
}
else
if( h == 5.1)
{
digitalwrite(ledpin,low);
delay(1000);
}
}
}
how use forum
code tags, please.
this wrong:
an array of 30 elements has them numbered 0 29, 30th out of range. it's unclear why doing this. try reading:
http://www.gammon.com.au/serial
code tags, please.
this wrong:
code: [select]
char x[30];
...
x[30] = serial.read();
an array of 30 elements has them numbered 0 29, 30th out of range. it's unclear why doing this. try reading:
http://www.gammon.com.au/serial
Arduino Forum > Using Arduino > Programming Questions > How to use strtod to convert a Serial.Read() data?
arduino
Comments
Post a Comment