0

I have a problem when I try to load the "BrainTest" function in the "AppSelect" function.

I have created a method to notify me on the serial monitor and on the LCD screen when a loading error occurs.

#include <LiquidCrystal.h>

// Arduino pins number
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
const int LCD_RS = 7;
const int LCD_Enable = 8;
const int LCD_D4 = 9;
const int LCD_D5 = 10;
const int LCD_D6 = 11;
const int LCD_D7 = 12;
LiquidCrystal lcd(LCD_RS, LCD_Enable, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

// Basic vars
int none = 0;
String Apps[3] = {"App select","Credits","Test your brain"};
int CurrentApp = 0;
int Yaxis = 1;
int Xaxis = 1;
int HiCh = 0;
int button;
int JXaxis;
int JYaxis;


void AppSelect() {  //          APPSELECT
  lcd.setCursor(0,0);
  lcd.print("App select menu");
  lcd.setCursor(0,1);
  lcd.print(Apps[HiCh]);
  if (button == 0) {
    SelectApp();
  }
  if (JYaxis <= 2) {
    if (HiCh != 0) {
      HiCh = HiCh - 1;
      lcd.clear();
      lcd.setCursor(0,1);
      lcd.print(Apps[HiCh]);
      delay(300);
    }
  }
  if (JYaxis >= 7) {
    if (HiCh != 1) {
      HiCh = HiCh + 1;
      lcd.clear();
      lcd.setCursor(0,1);
      lcd.print(Apps[HiCh]);
      delay(300);
    }
  }
}

void Credits() {  //          CREDITS
  Serial.print("- Credits app loading \n");
  lcd.clear();
  lcd.setCursor(9,0);
  lcd.print("Credits");
  lcd.setCursor(0,1);
  lcd.print("Made by Alexandre Bergeron");
  Serial.print("- Credits app loaded \n");
  delay(1300);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(600);
  lcd.scrollDisplayLeft();
  delay(1500);
  CurrentApp = 0;
  lcd.clear();
}


void BrainTest() {  //          BRAINTEST
  lcd.setCursor(0,0);
  lcd.print("Are you ready?");
  lcd.setCursor(0,1);
  lcd.print("Yes     No");
}


void setup() {  //          SETUP
  Serial.begin(9600);
  Serial.print("[2J");
  Serial.print("  Serial Monitor opened \n \n");
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  Serial.print("- App selector menu \n");
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
}


void SelectApp() {  //          SELECTAPP
  switch (HiCh) {
    case (0):
      CurrentApp = 0;
      AppSelect();
    case (1):
      CurrentApp = 1;
      Credits();
      break;
    case (2):
      CurrentApp = 2;
      BrainTest();
    default:
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Error");
      Serial.print("- App loading error \n");
  }
}


void loop() {  //          LOOP
  button = digitalRead(SW_pin);
  int JYaxis = analogRead(Y_pin) / 128;
  int JXaxis = analogRead(X_pin) / 128;
  if (CurrentApp == 0) { 
    lcd.setCursor(0,0);
    lcd.print(" App select menu");
    lcd.setCursor(0,1);
    lcd.print(Apps[HiCh]);
    if (button == 0) {
      SelectApp();
    }
    if (JYaxis >= 7) {
      if (HiCh != 0) {
        HiCh = HiCh - 1;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("App select menu");
        lcd.setCursor(0,1);
        lcd.print(Apps[HiCh]);
        delay(300);
      }
    }    
    if (JYaxis <= 2) {
      if (HiCh != 2) {
        HiCh = HiCh + 1;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("App select menu");
        lcd.setCursor(0,1);
        lcd.print(Apps[HiCh]);
        delay(300);
      }
    }
  }
}

If you need any other details, ask me and I will clarify it for you.

I don't know if my question name is correct so if you think I can improve it, you can tell me and I'll change it.

1 Answer 1

0

If you're not using break in the case, it'll fall through to the next one. That's basic design of C/C++ switch statement.

You can learn something more about C++ switch statement here.

3
  • Thanks! I think I did no just see the mistake.
    – Spyro 999
    Commented Oct 24, 2018 at 11:48
  • I'm not sure what do you mean by your comment, but if you don't understand what's wrong, the case (2): do it's job and then it fall through straight into the default: part because there is no break;.
    – KIIV
    Commented Oct 24, 2018 at 12:48
  • Sorry for my English I’ve understood the mistake
    – Spyro 999
    Commented Oct 24, 2018 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.