Hi guys,
I'm trying to use String Object functions (eg. length(), setCharAt()) on a String Object var that change on a external interrupt function, so I need to add the variable qualifier volatile to this var, but when I try to use the String object functions over this volatile String Variable, the compiler show the following errors:
error: passing 'volatile String' as 'this' argument of 'void String::setCharAt(unsigned int, char)' discards qualifiers [-fpermissive]
So.. if is not possible to use the String Object Functions on a volatile String, what can I do? or maybe I'm doing something wrong?
Ouch - it does seem like the String cannot be volatile.
I tweaked your code - changes have a <-- at end of line:
//volatile char wiegandOutput[27]; <-
String wiegandOutput;
volatile byte index = 0;
//interrupt Function
void readDATAZERO(){
if (digitalRead(2) == 0){
// wiegandOutput.setCharAt(index,0); <-
wiegandOutput.setCharAt(index,'\0');
index++;
}
}
//interrupt Function
void readDATAONE(){
if (digitalRead(3) == 0){
wiegandOutput.setCharAt(index,'\1');
// index++ <-
index++;
}
}
wiegandOutput is no longer volatile, and changed (you had char, but the function setCharAt() is for String objects). The last index needed a semicolon, and you haven't set up your loop yet.
However, I don't know if you want to use a char or a string. A char would be simpler, if I understand it: