Go Down

Topic: LCD menu + Real time module (Read 158 times) previous topic - next topic

Flixon

Hello everybody,
my problem may look simple but i am not very good at programming and english too.

So i have Arduino Mega 2560+LCD shield with 6 buttons(one is reset)+Real time module DS3231. That's only part of my whole project so if it's needed i can write you more details, but i think it's enough. Here i post part of my code with i need help.

I already have created menu (code below). In 2 submenus e.g. MenuB,MenuC i want change some variables. In menu B i want change 3 variables but i have only 4 buttons for changing this variables. I can change one wariable with UP and DOWN button and other with RIGHT and LEFT button but then there is third variable which i can't change. So i had idea of making some submenu. When i enter MenuB i could choose which variable i want manage. So this is my first problem what i dont know how to do.

Second problem in MenuC. I have stored real time in variable t. In menuC i want set up required time (hours,minutes) and store it in some other variable. This two variables real time (t) and required (set upped) will compare. If they are equeal it will turn on relay for example for some time which we set up too in this menu. So at all in MenuC i set up 2 things - required time and turn on time.

Thank you very much for your advices. If you don't understand something from code or my english don't be afraid to ask.

Code: [Select]


void setup()
{
    lcd.begin(16,2);  //Initialize a 2x16 type LCD

    rtc.begin();
    rtc.setDOW(FRIDAY);     // Set Day-of-Week to SUNDAY
    rtc.setTime(13, 16, 0);     // Set the time to 12:00:00 (24hr format)
    rtc.setDate(29, 12, 2017);   // Set the date to January 1st, 2014
   
    MainMenuDisplay();     
 
}
void loop(){

  t = rtc.getTime();
 btn_push = ReadKeypad();
   
    MainMenuBtn();
   
    if(btn_push == 'S')    //enter selected menu
    {
        WaitBtnRelease();
        switch (mainMenuPage)
        {
            case 1:
              MenuA();
              break;
            case 2:
              MenuB();
              break;
            case 3:
              MenuC();
              break;
            case 4:
              MenuD();
              break;
              case 5:
              Uvod();
              break;
             
           
        }

 
          MainMenuDisplay();
          WaitBtnRelease();
    }
   
 
    delay(20);
 
}

void MenuB()

    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Inside Menu D");
   
    while(ReadKeypad()!= 'S')
    {
        //Insert Task for Menu B here
       
    }
}
 
void MainMenuDisplay()
{
    lcd.clear();
    lcd.setCursor(0,0);
 
    switch (mainMenuPage)
    {
        case 1:
            lcd.print("1. Vlh. pody");
          break;
        case 2:
            lcd.print("2. Menu B");
          break;
        case 3:
            lcd.print("3. Menu C");
          break;
        case 4:
            lcd.print("4. Menu D");
          break;
        case 5:
         lcd.print("Zakl. info");   
        break;
       
    }
}
 
void MainMenuBtn()
{
    WaitBtnRelease();
    if(btn_push == 'U')
    {
        mainMenuPage++;
        if(mainMenuPage > mainMenuTotal)
          mainMenuPage = 1;
    }
    else if(btn_push == 'D')
    {
        mainMenuPage--;
        if(mainMenuPage == 0)
          mainMenuPage = mainMenuTotal;   
    }
   
    if(mainMenuPage != mainMenuPageOld) //only update display when page change
    {
        MainMenuDisplay();
        mainMenuPageOld = mainMenuPage;
    }
}
 
char ReadKeypad()
{
  /* Keypad button analog Value
  no button pressed 1023
  select  741
  left    503
  down    326
  up      142
  right   0
  */
  keypad_value = analogRead(keypad_pin);
 
  if(keypad_value < 100)
    return 'R';
  else if(keypad_value < 200)
    return 'U';
  else if(keypad_value < 400)
    return 'D';
  else if(keypad_value < 600)
    return 'L';
  else if(keypad_value < 800)
    return 'S';
  else
    return 'N';
 
}
 
void WaitBtnRelease()
{
    while( analogRead(keypad_pin) < 800){}
}


ieee488

It would help if we see what each of the submenus look like.


Go Up