Arduino字符串用逗号分隔为Array

时间:2014-02-21 22:37:06

标签: c++ c arduino

我正在尝试使用Arduino对IR Remote进行原始数据处理。

unsigned int ArrayKey[68] = {30868,8900,4400,600,500,600,...,600};
irsend.sendRaw(ArrayKey,68,38);

现在我尝试通过Serial获取Raw IR数据,但是存在语法问题:

readString = 30868,8900,4400,600,500,600,1650,600,550,....

unsigned int ArrayKey[68] = {strtok(readString, ",")};

错误:无法将参数'1'的'String'转换为'char '到'char * strtok(char *,const char *)'*

1 个答案:

答案 0 :(得分:3)

你不能像那样初始化它(非常数,非兼容等),而是你可以在运行时这样做

char *tmp;
int i = 0;
tmp = strtok(readString, ",");
while (tmp) {
   ArrayKey[i++] = atoi(tmp);
   tmp = strtok(NULL, ",");
}