zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    遇到一个php解析错误
    wndows netsh winsock reset
    javascript 阻塞
    ci 文件类型错误xlsx
    input限制整数
    canvas 时钟转动
    JS实现别踩白块游戏
    本地存储技术localStorage
    JavaScript事件
    JavaScript实现放大镜效果
  • 原文地址:https://www.cnblogs.com/xiaowuyi/p/4162728.html
Copyright © 2011-2022 走看看