Although an Arduino newbie I have programming experience in other languages.
In my sketch I have the following lines of code which compiles, loads and runs on my Arduino UNO R3
char FwdRev = " "; // "F" = Forwards ; "R" = Reverse
void setup () {
// in which I do some setup stuff
}
void loop () {
// This goes into a ‘wait’ state until something sets a wanted value
while (!(FwdRev = "F") or (FwdRev="R")) {
/*
I read an input pin until its state tells the code to set the variable to “F” or “R” and break out of the ‘while’ loop.
*/
}
// and now the code processes the value of the variable.
}
When I compile this code for an Arduino R4 WiFi I get the following error.
The compiler clearly treats the variable as if it had been declared as a constant that I am trying to convert to a variable – which is not the case.
I would have expected that no matter what the version of UNO we choose to use, the IDE compiler would continue to successfully compile code used on one version (R3) in this case for use on a newer one (R4).
A char variable can only hold a single character but the string that you are trying to use has at least 2 characters, the space and the terminating zero of the string
Use single quotes like this instead
char FwdRev[] = ' ';
Then, in the comparisons, do this
while (!(FwdRev == 'F') or (FwdRev == 'R')) {
Note the use of == rather than = to correct another mistake
Switch on the warnings in 'Preferences', and the UNO R3 compiler will also complain about these lines. Switching warnings on is always a good idea. Many warnings are in fact errors.
The R4 uses a different toolchain for compiling which is differently configured. What might result in a warning for the R3 might result in an error for the R4.