arduino:int & double 转string 适合12864下使用


转自:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=3383&highlight=12864

很多人在玩12864的时候,都会发现不能直接显示字符,因为大多数12864类库没有显示数值的函数,那么我们就需要把int型变量转换成字符串,方法很简单,只要在代码末尾加上一个功能函数即可~

 

    char* itostr(char *str, int i) { sprintf(str, "%d", i); return str; }

 

把上述代码放入程序末尾,在程序头定义一个char a[25],在读取完数值之后就可以轻松的用一行itostr(a,b);来转换,其中a是之前定义的char,b是数值变量,是不是很方便呢?

======================================
附一个double转string的.

 

    void setup() { // put your setup code here, to run once: double test = 1.23; char test2[25] ; dtostr(test2,test); } void loop() { // put your main code here, to run repeatedly:  } char* dtostr(char *str, double d) { sprintf(str, "%f", d); return str; }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM