Home>

I want to switch to 3 modes in the order of A, B, C, but I don't understand why I can't go back to A by going to C with the following code.

Corresponding source code
switch_mode = "A";
void loop () {
    if (switch_mode == "A") {
      switch_mode = "B";
      }
    else if (switch_mode = "B") {
      switch_mode = "C";
      }
    else if (switch_mode = "C") {
      switch_mode = "A";
      }
}
Supplementary information (FW/tool version, etc.)

M5stickC Plus
Win10
Arduino IDE 1.8.13

  • Answer # 1

    else if (switch_mode = "B") {
    else if (switch_mode = "C") {

    Both have one'=', so isn't it an assignment?

  • Answer # 2

    ==Where to do= =It has become.

    --other if (switch_mode = "B") {
    + else if (switch_mode == "B") {
            switch_mode = "C";
        }
    --other if (switch_mode = "C") {
    + else if (switch_mode == "C") {
            switch_mode = "A";
        }