在Arduino程序中,我正在研究GPS,通过USB将坐标发送到arduino.因此,传入的坐标存储为字符串.有没有办法将GPS坐标转换为float或int?
我试过      int gpslong = atoi(curLongitude)和      float gpslong = atof(curLongitude),但他们都引起Arduino的给出错误信息:
error: cannot convert 'String' to 'const char*' for argument '1' to 'int atoi(const char*)'
有没有人有什么建议?
nne*_*neo 23
你可以得到一个int从String由只调用toInt了对String对象(例如curLongitude.toInt()).
如果你想要一个float,你可以atof结合使用toCharArray方法:
char floatbuf[32]; // make this at least big enough for the whole string
curLongitude.toCharArray(floatbuf, sizeof(floatbuf));
float f = atof(floatbuf);
| 归档时间: | 
 | 
| 查看次数: | 75479 次 | 
| 最近记录: |