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