user3339163
user3339163

Reputation: 23

Arduino String separated by comma to Array

I am trying to do some Raw data handling of an IR Remote with Arduino.

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:

readString is = 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*)'*

Upvotes: 2

Views: 8849

Answers (1)

Sundar
Sundar

Reputation: 469

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, ",");
}

Upvotes: 4

Related Questions