简体   繁体   English

Arduino字符串用逗号分隔为Array

[英]Arduino String separated by comma to Array

I am trying to do some Raw data handling of an IR Remote with Arduino. 我正在尝试使用Arduino对IR Remote进行原始数据处理。

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

Now I try to get a Raw IR Data via Serial, but there is a syntax problem: 现在我尝试通过Serial获取Raw IR数据,但是存在语法问题:

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

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

error: cannot convert 'String' to 'char ' for argument '1' to 'char* strtok(char*, const char*)'* 错误:无法将参数'1'的'String'转换为'char '到'char * strtok(char *,const char *)'*

You cannot initialize it like that (non constant, non compatible etc.,), instead you can do it during run time 你不能像那样初始化它(非常数,不兼容等),而是你可以在运行时这样做

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM