极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10229|回复: 1

Mega 2560 型態轉換有問題?

[复制链接]
发表于 2016-7-5 09:25:24 | 显示全部楼层 |阅读模式
我把Serial3.read()存到String S下
在個別存到A,B,C,D
但是為啥會都是0....
  1. char A;
  2.     String S = "";
  3.     int c=0, i=0;
  4.     while(Serial3.available())
  5.     {
  6.       A = Serial3.read();
  7.       S += A;
  8.       delay(10);
  9.       c=1;
  10.     }
  11.     digitalWrite(2, LOW);
  12.     if(c == 1)
  13.     {
  14.       for(int i=0; i<sizeof(S)+2; i++)
  15.       {
  16.         Serial.print(S[i]);
  17.         
  18.       }
  19.       String A;
  20.   String B;
  21.   String C;
  22.   String D;
  23.   long int X = 0;
  24.   A = S[3];
  25.   B = S[4];
  26.   C = S[1];
  27.   D = S[6];
  28.   Serial.print(D.toInt());
复制代码
回复

使用道具 举报

发表于 2016-7-5 13:01:03 | 显示全部楼层
S[ ]使用前应该需要定义。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-20 13:17 , Processed in 0.037975 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表