How do you convert a String to a float or int?

后端 未结 5 1599
醉酒成梦
醉酒成梦 2021-02-19 03:56

In an Arduino program I\'m working on the GPS sends the coordinates to the arduino through USB. Because of this, the incoming coordinates are stored as Strings. Is there any way

5条回答
  •  醉酒成梦
    2021-02-19 04:48

    Convert String to Long in Arduino IDE:

        //stringToLong.h
    
        long stringToLong(String value) {
            long outLong=0;
            long inLong=1;
            int c = 0;
            int idx=value.length()-1;
            for(int i=0;i<=idx;i++){
    
                c=(int)value[idx-i];
                outLong+=inLong*(c-48);
                inLong*=10;
            }
    
            return outLong;
        }
    

提交回复
热议问题