轉自: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; }