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 use forum

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

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62