1

This is just a "working" exemple of my problem. In the loop function changes the button value, and it should print to the serial monitor "DOWN" and "UP", but only the first is printed. But if comment the bool variable in the change_timestamp_selected function the program runs the way it should...

If anyone can spot the error, please help me. Thank you.

enum btn {btnRIGHT, btnUP, btnDOWN, btnLEFT, btnSELECT, btnNONE} button;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}


void loop() {
  button = btnDOWN;
  change_timestamp_selected();
  delay(1000);
  button = btnUP;
  change_timestamp_selected();
  delay(1000);
}
void change_timestamp_selected() {
  switch (button) {
    case btnDOWN:
      Serial.println("DOWN");
      bool if_commented_works = true;
      break;
    case btnUP:
      Serial.println("UP");
      break;
  }
}
Luís Chaves
  • 661
  • 7
  • 15

1 Answers1

1

I'll be honest this stumped me for a bit but I found the issue once I compiled it myself. It is an Error: Jump to case label the most upvoted reply there is a good explanation, but to summarize it: You declared this variable in what the compiler sees as the same scope so the compiler knows it is there, but when it goes back to that scope it gets confused as to why it is not declared.

Aidan
  • 413
  • 3
  • 22
  • Thanks... Adding the { } inside the case has solved the problem... Yoo the boss! ahaha – Luís Chaves Mar 21 '19 at 04:31
  • 1
    Thanks, no problem. It helps a lot I have found when writing Arduino code if I am really stuck to compile it on a compiler that returns errors. – Aidan Mar 21 '19 at 04:34