Help whit Menu

Hi.

First a wanna start be saying that im a newbe at this so sorry if im stuped:)

I got some help whit this code, but the menusystem i try to make my self,as you all can see:)
But now i have run in to a problem i can fix:(

Im gonna try to explane the problem:

When i start the code, the first text on the lcd shows up = working
Then i can hit "A" or "B" on the keypad to get to diffrent menus = working

In menu "A" i can enter numbers and everything works good.
When i press "B" i get in to that menu BUT i cant enter any numbers, if i hit any key the menu goes back to menu"A"???

How can i get menu "B" to work the same way as menu "A"?

Thanks for any help!

#include <AccelStepper.h>
#include <Keypad.h> 
#include <LiquidCrystalFast.h>

LiquidCrystalFast lcd(12, 10, 11, 5, 4, 3, 2);

volatile int aPos=0;
volatile int bPos=0;
volatile int currPos=0;
volatile int aCur=0;
volatile int bCur=0;

int val = 0; 

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {22, 24, 26, 28};
byte colPins[COLS] = {31, 33, 35, 37};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );  // Keypad Library definition

#define backlight_pin A2
 
AccelStepper stepperA(1, A0, A1);
AccelStepper stepperB(2, A3, A4); 

void setup() {
 
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print( "->PALLINSTELLNING<-" );
  lcd.setCursor(0,2);
  lcd.print("A = LENGD");
  lcd.setCursor(11,2);
  lcd.print("B = BREDD");
  analogWrite(backlight_pin, 250); 
  stepperA.setMaxSpeed(1500); 
  stepperA.setAcceleration(400);
  stepperB.setMaxSpeed(1500); 
  stepperB.setAcceleration(400);

 
 
 
}

void loop(){
 
  pinMode(6, OUTPUT); 
  analogWrite(6, 140);
 
  char keypressed = keypad.getKey(); 
  if (keypressed != NO_KEY){     
  switch (keypressed) {

   
    case '1':   
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
    case '0':
   
    setPos( keypressed );
   
   
   
     break;
    case 'A':
      menylengd();
      break;
       
    case 'B':
      menybred();
      break;
     
    case '*':
      deletenumber();
       break;
       
    case '#':
      calculatedistance();
      break;

    case 'C':
      currPos=0;
      break;
     
    case 'D':
      currPos=1;
      break;
    }
  }
}
     
     
void setPos( char num ) {
  int iNum = String(num).toInt();
  switch( currPos ) {
  case 0:
   if( aPos>999) return;
    aPos*=10;
    aPos+=iNum;
    break;
    case 1:
   if( aPos>999) return;
    bPos*=10;
    bPos+=iNum;
    break;
  }
 

   Lcdlengd();

}



void deletenumber() { 
  switch( currPos ) {
    case 0:
      aPos/=10;
      break;
    case 1:
      bPos/=10;
      break;

    }
 
 Lcdlengd();
 
} 

void menylengd() { 
  switch( currPos ) {
  case 0:
  break;
  }

Lcdlengd();

 
}

void menybred() { 
  switch( currPos ) {
  case 0:
  break;
  }

Lcdbredd();

 }
 
void calculatedistance() {  // Used to create a full number from entered numbers
  if( aPos != aCur ) {
    moveStepper( 0 );
  }
  if( bPos != bCur ) {
    moveStepper( 1 );
  }
Lcdlengd();
 
}



void moveStepper( int which ) {
  lcd.begin( 20,4 );
  lcd.setCursor( 0,1 );
  lcd.print( "->FLYTTAR FOTOCELL<-" );
  lcd.print(" ");
 

 
 
 
  long calculatedmove;
 
  switch( which ) {
    case 0:
      calculatedmove = (aPos * 1938UL)/20;
      stepperA.runToNewPosition( calculatedmove );
      aCur = aPos;
      break;
    case 1:
      calculatedmove = (bPos * 1938UL)/20;
      stepperB.runToNewPosition( calculatedmove );
      bCur = bPos;
      break;
  }
 
Lcdlengd();

   
}




 
void Lcdbredd() {
 
  String strA = String(bPos)+ "mm";
  String strB = String(bCur)+ "mm";
  String strC = "----->BREDD<------";
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print(strC);
  lcd.setCursor(0,2);
  lcd.print(aPos);
  lcd.setCursor(0,2);
  lcd.print(strA);
  lcd.setCursor(0,1);
  lcd.print("ANGE:");
  lcd.setCursor(14,2);
  lcd.print(strB);
  lcd.setCursor(8,1);
  lcd.print("AKTUELL POS:");
 
 
 
 
 

 
}

 void Lcdlengd() {
  String strA = String(aPos)+ "mm";
  String strB = String(aCur)+ "mm";
  String strC = "----->LENGD<------";
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print(strC);
  lcd.setCursor(0,2);
  lcd.print(aPos);
  lcd.setCursor(0,2);
  lcd.print(strA);
  lcd.setCursor(0,1);
  lcd.print("ANGE:");
  lcd.setCursor(14,2);
  lcd.print(strB);
  lcd.setCursor(8,1);
  lcd.print("AKTUELL POS:");
 

}

You are calling Lcdlengd() from void setPos().
You could add a variable that keep track of which menu you are in at the moment.

thanks for the reply,

I dont realy know how to do that:(

Can i call both display from void setPos().?

Something like this, you have to declare menuVal yourself

    case 'A':
      menuVal=1;
      menylengd();
      break;
       
    case 'B':
      menuVal=2;
      menybred();
      break;

.......

void setPos( char num ) {
  int iNum = String(num).toInt();
  switch( currPos ) {
  case 0:
   if( aPos>999) return;
    aPos*=10;
    aPos+=iNum;
    break;
    case 1:
   if( aPos>999) return;
    bPos*=10;
    bPos+=iNum;
    break;
  }
 
if (menuVal==1){
   Lcdlengd();
  }
else if (menuVal==2){
  Lcdbredd();
  }

}

Thanks for the input Gabriel, but i still can get it to work:(

Is this how you meen it to be?

#include <AccelStepper.h>
#include <Keypad.h> 
#include <LiquidCrystalFast.h>

LiquidCrystalFast lcd(12, 10, 11, 5, 4, 3, 2);

volatile int aPos=0;
volatile int bPos=0;
volatile int currPos=0;
volatile int aCur=0;
volatile int bCur=0;
volatile int menuVal=1;
volatile int menuVal=2;

const byte ROWS = 4;

int val = 0; 
 
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {22, 24, 26, 28};
byte colPins[COLS] = {31, 33, 35, 37};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );  // Keypad Library definition

#define backlight_pin A2
 
AccelStepper stepperA(1, A0, A1);
AccelStepper stepperB(2, A3, A4); 

void setup() {
 
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print( "->PALLINSTELLNING<-" );
  lcd.setCursor(0,2);
  lcd.print("A = LENGD");
  lcd.setCursor(11,2);
  lcd.print("B = BREDD");
  analogWrite(backlight_pin, 250); 
  stepperA.setMaxSpeed(1500); 
  stepperA.setAcceleration(400);
  stepperB.setMaxSpeed(1500); 
  stepperB.setAcceleration(400);

 
 
 
}

void loop(){
 
  pinMode(6, OUTPUT); 
  analogWrite(6, 140);
 
  char keypressed = keypad.getKey(); 
  if (keypressed != NO_KEY){     
  switch (keypressed) {

   
    case '1':   
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
    case '0':
   
    setPos( keypressed );
   
   
   
     break;
    case 'A':
      menuVal=1;
      menylengd();
      break;
       
    case 'B':
      menuVal=2;
      menybredd();
      break;
     
    case '*':
      deletenumber();
       break;
       
    case '#':
      calculatedistance();
      break;

    case 'C':
      currPos=0;
      break;
     
    case 'D':
      currPos=1;
      break;
    }
  }
}
     
     
void setPos( char num ) {
  int iNum = String(num).toInt();
  switch( currPos ) {
  case 0:
   if( aPos>999) return;
    aPos*=10;
    aPos+=iNum;
    break;
    case 1:
   if( aPos>999) return;
    bPos*=10;
    bPos+=iNum;
    break;
  }
 
if (menuVal=1){
   Lcdlengd();
  }
else if (menuVal=2){
  Lcdbredd();
 
  }
 

   Lcdlengd();

}



void deletenumber() { 
  switch( currPos ) {
    case 0:
      aPos/=10;
      break;
    case 1:
      bPos/=10;
      break;

    }
 
 Lcdlengd();
 
} 

void menylengd() { 
  switch( currPos ) {
  case 0:
  break;
  }

Lcdlengd();

 
}

void menybredd() { 
  switch( currPos ) {
  case 0:
  break;
  }

Lcdbredd();

 }
 
void calculatedistance() {  // Used to create a full number from entered numbers
  if( aPos != aCur ) {
    moveStepper( 0 );
  }
  if( bPos != bCur ) {
    moveStepper( 1 );
  }
Lcdlengd();
 
}



void moveStepper( int which ) {
  lcd.begin( 20,4 );
  lcd.setCursor( 0,1 );
  lcd.print( "->FLYTTAR FOTOCELL<-" );
  lcd.print(" ");
 

 
 
 
  long calculatedmove;
 
  switch( which ) {
    case 0:
      calculatedmove = (aPos * 1938UL)/20;
      stepperA.runToNewPosition( calculatedmove );
      aCur = aPos;
      break;
    case 1:
      calculatedmove = (bPos * 1938UL)/20;
      stepperB.runToNewPosition( calculatedmove );
      bCur = bPos;
      break;
  }
 
Lcdlengd();

   
}




 
void Lcdbredd() {
 
  String strA = String(bPos)+ "mm";
  String strB = String(bCur)+ "mm";
  String strC = "----->BREDD<------";
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print(strC);
  lcd.setCursor(0,2);
  lcd.print(aPos);
  lcd.setCursor(0,2);
  lcd.print(strA);
  lcd.setCursor(0,1);
  lcd.print("ANGE:");
  lcd.setCursor(14,2);
  lcd.print(strB);
  lcd.setCursor(8,1);
  lcd.print("AKTUELL POS:");
 
 
 
 
 

 
}

 void Lcdlengd() {
  String strA = String(aPos)+ "mm";
  String strB = String(aCur)+ "mm";
  String strC = "----->LENGD<------";
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print(strC);
  lcd.setCursor(0,2);
  lcd.print(aPos);
  lcd.setCursor(0,2);
  lcd.print(strA);
  lcd.setCursor(0,1);
  lcd.print("ANGE:");
  lcd.setCursor(14,2);
  lcd.print(strB);
  lcd.setCursor(8,1);
  lcd.print("AKTUELL POS:");
 

}

Just to able able to highlight in your code...
You forgot it should be == in if statements, and remove original call to Lcdlengd

Trigger80:
if (menuVal=**=1){
Lcdlengd();
}
else if (menuVal=
=**2){
Lcdbredd();

}

~~ Lcdlengd();~~

}

Thanks for all the help Gabriel.

If i use "volatile int menuVal=2;, i get an error message:

redefinition of 'volatile int menuVal'

If i use "volatile int menuVall=2 no error message

But if im in "B" menu and hit a key, i goes back and enters the number in "A" menu...?:frowning:

#include <AccelStepper.h>
#include <Keypad.h> 
#include <LiquidCrystalFast.h>

LiquidCrystalFast lcd(12, 10, 11, 5, 4, 3, 2);

volatile int aPos=0;
volatile int bPos=0;
volatile int currPos=0;
volatile int aCur=0;
volatile int bCur=0;
volatile  int menuVal=1;
volatile  int menuVall=2;




const byte ROWS = 4;

int val = 0; 
 
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {22, 24, 26, 28};
byte colPins[COLS] = {31, 33, 35, 37};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );  // Keypad Library definition

#define backlight_pin A2
 
AccelStepper stepperA(1, A0, A1);
AccelStepper stepperB(2, A3, A4); 

void setup() {
 
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print( "->PALLINSTELLNING<-" );
  lcd.setCursor(0,2);
  lcd.print("A = LENGD");
  lcd.setCursor(11,2);
  lcd.print("B = BREDD");
  analogWrite(backlight_pin, 250); 
  stepperA.setMaxSpeed(1500); 
  stepperA.setAcceleration(400);
  stepperB.setMaxSpeed(1500); 
  stepperB.setAcceleration(400);

 
 
 
}

void loop(){
 
  pinMode(6, OUTPUT); 
  analogWrite(6, 140);
 
  char keypressed = keypad.getKey(); 
  if (keypressed != NO_KEY){     
  switch (keypressed) {

   
    case '1':   
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
    case '0':
   
    setPos( keypressed );
   
   
   
     break;
    case 'A':
      menuVal=1;
      menylengd();
      break;
       
    case 'B':
      menuVall=2;
      menybredd();
      break;
     
    case '*':
      deletenumber();
       break;
       
    case '#':
      calculatedistance();
      break;

    case 'C':
      currPos=0;
      break;
     
    case 'D':
      currPos=1;
      break;
    }
  }
}
     
     
void setPos( char num ) {
  int iNum = String(num).toInt();
  switch( currPos ) {
  case 0:
   if( aPos>999) return;
    aPos*=10;
    aPos+=iNum;
    break;
    case 1:
   if( aPos>999) return;
    bPos*=10;
    bPos+=iNum;
    break;
  }
 
if (menuVal==1){
   Lcdlengd();
  }
else if (menuVall==1){
  Lcdbredd();
 
  }
 



}



void deletenumber() { 
  switch( currPos ) {
    case 0:
      aPos/=10;
      break;
    case 1:
      bPos/=10;
      break;

    }
 
 Lcdlengd();
 
} 

void menylengd() { 
  switch( currPos ) {
  case 0:
  break;
  }

Lcdlengd();

 
}

void menybredd() { 
  switch( currPos ) {
  case 0:
  break;
  }

Lcdbredd();

 }
 
void calculatedistance() {  // Used to create a full number from entered numbers
  if( aPos != aCur ) {
    moveStepper( 0 );
  }
  if( bPos != bCur ) {
    moveStepper( 1 );
  }
Lcdlengd();
 
}



void moveStepper( int which ) {
  lcd.begin( 20,4 );
  lcd.setCursor( 0,1 );
  lcd.print( "->FLYTTAR FOTOCELL<-" );
  lcd.print(" ");
 

 
 
 
  long calculatedmove;
 
  switch( which ) {
    case 0:
      calculatedmove = (aPos * 1938UL)/20;
      stepperA.runToNewPosition( calculatedmove );
      aCur = aPos;
      break;
    case 1:
      calculatedmove = (bPos * 1938UL)/20;
      stepperB.runToNewPosition( calculatedmove );
      bCur = bPos;
      break;
  }
 
Lcdlengd();

   
}




 
void Lcdbredd() {
 
  String strA = String(bPos)+ "mm";
  String strB = String(bCur)+ "mm";
  String strC = "----->BREDD<------";
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print(strC);
  lcd.setCursor(0,2);
  lcd.print(aPos);
  lcd.setCursor(0,2);
  lcd.print(strA);
  lcd.setCursor(0,1);
  lcd.print("ANGE:");
  lcd.setCursor(14,2);
  lcd.print(strB);
  lcd.setCursor(8,1);
  lcd.print("AKTUELL POS:");
 
 
 
 
 

 
}

 void Lcdlengd() {
  String strA = String(aPos)+ "mm";
  String strB = String(aCur)+ "mm";
  String strC = "----->LENGD<------";
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print(strC);
  lcd.setCursor(0,2);
  lcd.print(aPos);
  lcd.setCursor(0,2);
  lcd.print(strA);
  lcd.setCursor(0,1);
  lcd.print("ANGE:");
  lcd.setCursor(14,2);
  lcd.print(strB);
  lcd.setCursor(8,1);
  lcd.print("AKTUELL POS:");
 

}





   [code]

[/code]

#include <AccelStepper.h>
#include <Keypad.h> 
#include <LiquidCrystalFast.h>

LiquidCrystalFast lcd(12, 10, 11, 5, 4, 3, 2);

volatile int aPos=0;
volatile int bPos=0;
volatile int currPos=0;
volatile int aCur=0;
volatile int bCur=0;
int menuVal;




const byte ROWS = 4;

int val = 0; 
 
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {22, 24, 26, 28};
byte colPins[COLS] = {31, 33, 35, 37};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );  // Keypad Library definition

#define backlight_pin A2
 
AccelStepper stepperA(1, A0, A1);
AccelStepper stepperB(2, A3, A4); 

void setup() {
 
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print( "->PALLINSTELLNING<-" );
  lcd.setCursor(0,2);
  lcd.print("A = LENGD");
  lcd.setCursor(11,2);
  lcd.print("B = BREDD");
  analogWrite(backlight_pin, 250); 
  stepperA.setMaxSpeed(1500); 
  stepperA.setAcceleration(400);
  stepperB.setMaxSpeed(1500); 
  stepperB.setAcceleration(400);

 
 
 
}

void loop(){
 
  pinMode(6, OUTPUT); 
  analogWrite(6, 140);
 
  char keypressed = keypad.getKey(); 
  if (keypressed != NO_KEY){     
  switch (keypressed) {

   
    case '1':   
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
    case '0':
   
    setPos( keypressed );
   
   
   
     break;
    case 'A':
      menuVal=1;
      menylengd();
      break;
       
    case 'B':
      menuVal=2;
      menybredd();
      break;
     
    case '*':
      deletenumber();
       break;
       
    case '#':
      calculatedistance();
      break;

    case 'C':
      currPos=0;
      break;
     
    case 'D':
      currPos=1;
      break;
    }
  }
}
     
     
void setPos( char num ) {
  int iNum = String(num).toInt();
  switch( currPos ) {
  case 0:
   if( aPos>999) return;
    aPos*=10;
    aPos+=iNum;
    break;
    case 1:
   if( aPos>999) return;
    bPos*=10;
    bPos+=iNum;
    break;
  }
 
if (menuVal==1){
   Lcdlengd();
  }
else if (menuVal==2){
  Lcdbredd();
 
  }
 



}



void deletenumber() { 
  switch( currPos ) {
    case 0:
      aPos/=10;
      break;
    case 1:
      bPos/=10;
      break;

    }
 
 Lcdlengd();
 
} 

void menylengd() { 
  switch( currPos ) {
  case 0:
  break;
  }

Lcdlengd();

 
}

void menybredd() { 
  switch( currPos ) {
  case 0:
  break;
  }

Lcdbredd();

 }
 
void calculatedistance() {  // Used to create a full number from entered numbers
  if( aPos != aCur ) {
    moveStepper( 0 );
  }
  if( bPos != bCur ) {
    moveStepper( 1 );
  }
Lcdlengd();
 
}



void moveStepper( int which ) {
  lcd.begin( 20,4 );
  lcd.setCursor( 0,1 );
  lcd.print( "->FLYTTAR FOTOCELL<-" );
  lcd.print(" ");
 

 
 
 
  long calculatedmove;
 
  switch( which ) {
    case 0:
      calculatedmove = (aPos * 1938UL)/20;
      stepperA.runToNewPosition( calculatedmove );
      aCur = aPos;
      break;
    case 1:
      calculatedmove = (bPos * 1938UL)/20;
      stepperB.runToNewPosition( calculatedmove );
      bCur = bPos;
      break;
  }
 
Lcdlengd();

   
}




 
void Lcdbredd() {
 
  String strA = String(bPos)+ "mm";
  String strB = String(bCur)+ "mm";
  String strC = "----->BREDD<------";
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print(strC);
  lcd.setCursor(0,2);
  lcd.print(aPos);
  lcd.setCursor(0,2);
  lcd.print(strA);
  lcd.setCursor(0,1);
  lcd.print("ANGE:");
  lcd.setCursor(14,2);
  lcd.print(strB);
  lcd.setCursor(8,1);
  lcd.print("AKTUELL POS:");
 
 
 
 
 

 
}

 void Lcdlengd() {
  String strA = String(aPos)+ "mm";
  String strB = String(aCur)+ "mm";
  String strC = "----->LENGD<------";
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print(strC);
  lcd.setCursor(0,2);
  lcd.print(aPos);
  lcd.setCursor(0,2);
  lcd.print(strA);
  lcd.setCursor(0,1);
  lcd.print("ANGE:");
  lcd.setCursor(14,2);
  lcd.print(strB);
  lcd.setCursor(8,1);
  lcd.print("AKTUELL POS:");
 

}

now if i add a number in menu"B" i cant see the first number it does not show over the "0" if i enter 1234, it looks like this: 0234...

And when i go back to "A" menu its been enter there to, "A" menu = 1234 "B" menu 0234....

Strange...

i switch the "aPos" and "bPos" then the "b" menu work but not the "A" menu, so its looks like there is a problem here in this part?
It always enter in both menu at the same time...

void setPos( char num ) {
  int iNum = String(num).toInt();
  switch( currPos ) {
  case 0:
   if( aPos>999) return;
    bPos*=10;
    bPos+=iNum;
    break;
    case 1:
   if( bPos>999) return;
    aPos*=10;
    aPos+=iNum;
    break;
  }[code]

[/code]