advice on defining variables

I am writing a code for arduino mega. I am having problem in defining variables which will be later used in the loop.
The arduinio mega is interfaced with a 4x4 matrix keypad and 20x4 LCD.

The error i am getting is “invalid conversion from ‘int*’ to ‘long int’”

the case 3 and 4 are not yet decided.so i have left it blank.

#include <Keypad.h>
#include <LiquidCrystal.h>


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] = {30,31,32,33}; //connect to row pinouts 
byte colPins[COLS] = {34,35,36,37}; //connect to column pinouts

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char UL[10];
char LL[10];
int k = 0;
int l = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
  Serial.begin(9600);
// set up the LCD's number of columns and rows: 
  lcd.begin(20,4);
  lcd.cursor();
  // set the cursor to column 0, line 0
  // (note: line 0 is the first row, since counting begins with 0):
  lcd.setCursor(0, 0);
  lcd.print("Enter Upper Limit");
  lcd.setCursor(0, 1);
  
}


  void loop(){
    char key = keypad.getKey();
    
    char range = map(key, UL, LL, 0, 3);
    
    switch(range) {
      
    case 0:
    if(k<5) {     
     if (key != NO_KEY) {         
     // Print a message to the LCD.  
       lcd.print(key);
      UL[k] = key;
    //Serial.println(key);
   
   k++;
  }

}
break;

case 1:
 
 if(l<5) {     
     if (key != NO_KEY) {         
     // Print a message to the LCD.  
     lcd.print(key);
  LL[l] = key;
// Serial.println(key);
   
   l++;
  }
  
  
  }
case 2:

break;

case 3:

break;
    }
 }

Please help… Thanks…

Which line produced the error? The error message should have a line number. Do us a favor, mark the line in your code. We hate counting. Also what do you intend to do with map function? Whatever your intent, you used it wrong.

Liudr beat me to it.

Your map function doesn't look right.

char range = map(key, UL, LL, 0, 3);

Why are UL and LL type char and arrays? Why do they have no initial value? What is the highest and lowest values UL and LL are supposed to represent?

Why not just switch using "key" and look for the key pressed, '1' - '#' ?

Well, you beat me on the keypad password thread. Oh, forgot to mention no initial values.

The line char range = map(key, UL, LL, 0, 3); is generating the error

I have made few changes to the code…Please look at the new code…
The UL and LL are used as a storage space for storing the keys pressed…it shouldn’t exceed 5 characters…

#include <Keypad.h>
#include <LiquidCrystal.h>


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] = {30,31,32,33}; //connect to row pinouts 
byte colPins[COLS] = {34,35,36,37}; //connect to column pinouts

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char UL[10];
char LL[10];
int k = 0;
int l = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
  Serial.begin(9600);
// set up the LCD's number of columns and rows: 
  lcd.begin(20,4);
  lcd.cursor();
  // set the cursor to column 0, line 0
  // (note: line 0 is the first row, since counting begins with 0):
  
    
}


  
  void loop(){
    char key = keypad.getKey();
    
    switch(key) {
      
  case 'A':
  lcd.setCursor(0, 0);
  lcd.print("Enter Upper Limit");
  lcd.setCursor(0, 1);
  
  upperlimit();
  
break;

case 'B':
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Lower Limit");
lcd.setCursor(0, 1);

 if(l<5) {     
     if (key != NO_KEY) {         
     // Print a message to the LCD.  
     lcd.print(key);
  LL[l] = key;
// Serial.println(key);
   
   l++;
  }
  
  
  }
case 'C':

break;

case 'D':

break;
    }
 }
 
void upperlimit(){
char key = keypad.getKey();
// lcd.write("hello");
 
 if(k<5) { 
     
     if (key) {         
     // Print a message to the LCD.  
       lcd.print(key);
       UL[k] = key;
    //Serial.println(key);
   k++;
  }
}
  
 // for( k=0; k<5; k++)
//  {
//    key = keypad.getKey();
//    if (key != NO_KEY) {
//      lcd.print(key);
//      UL[k] = key;
//    }
//  }
}

neither the for loop nor if loop operation is working for me…the for loop has been made as a comment by me for testing the if loop but neither of them are working for me…

Please help…thanks…

 char range = map(key, UL, LL, 0, 3);

What are you trying to achieve here? Have you read this

@ AWOL

I have modified the line…

Please check the modified code

#include <Keypad.h>
#include <LiquidCrystal.h>


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] = {30,31,32,33}; //connect to row pinouts 
byte colPins[COLS] = {34,35,36,37}; //connect to column pinouts

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char UL[10];
char LL[10];
int k = 0;
int l = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
  Serial.begin(9600);
// set up the LCD's number of columns and rows: 
  lcd.begin(20,4);
  lcd.cursor();
  // set the cursor to column 0, line 0
  // (note: line 0 is the first row, since counting begins with 0):
  
    
}


 void loop(){
    char key = keypad.getKey();
    
    switch(key) {
      
  case 'A':
  lcd.setCursor(0, 0);
  lcd.print("Enter Upper Limit");
  lcd.setCursor(0, 1);
  
  upperlimit();
  
  //}

//    if(k<5) {     
//     if (key != NO_KEY) {         
     // Print a message to the LCD.  
//       lcd.print(key);
//      UL[k] = key;
    //Serial.println(key);
   
//   k++;
//  }

//}
break;

case 'B':
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Lower Limit");
lcd.setCursor(0, 1);

 if(l<5) {     
     if (key != NO_KEY) {         
     // Print a message to the LCD.  
     lcd.print(key);
  LL[l] = key;
// Serial.println(key);
   
   l++;
  }
  
  
  }
case 'C':

break;

case 'D':

break;
    }
 }
 
void upperlimit(){
char key = keypad.getKey();
// lcd.write("hello");
 
 if(k<5) { 
     
     if (key != NO_KEY) {         
     // Print a message to the LCD.  
       lcd.print(key);
       UL[k] = key;
    //Serial.println(key);
   k++;
  }
}
  
 // for( k=0; k<5; k++)
//  {
//    key = keypad.getKey();
//    if (key != NO_KEY) {
//      lcd.print(key);
//      UL[k] = key;
//    }
//  }
}

thanks…

Check it for what? Excessive commenting-out? Indentation?

@AWOL

neither the for loop nor if loop operation is working for me..the for loop has been made as a comment by me for testing the if loop but neither of them are working for me..

it is just displaying enter the upper limit and i am unable to enter any values..

neither the for loop nor if loop operation is working for me

"working" or "not working" are quite subjective concepts. The processor is doing something; you can be pretty-well assured of that. Whether or not it is doing what you want, or expect, is another matter, and so the expectations need to be defined.

yes the processor is doing something..

My expectation is that it has to store upper limit and lower limit value in variable UL and LL respectively from the keypad and in the mean time it has to display the keys entered from the keypad on the LCD.. So that i can compare some predefined value with upper and lower limits and display that on LCD whether it is within the limits or not..

vathsa: variable UL and LL

I suggest you change the names of these variables. The values UL and LL are suffices used to indicate the type of unsigned long and long long number literals, and might be confusing the compiler. If nothing else, they're confusing [u]me[/u].

Peter, I see. Now that explains the error message.

OP, do you know how to use a while loop? Your case statement works only because it is inside loop(), while is executed inside a while loop my arduino. Once you detect a key, such as A, you need to use while loop to keep waiting for the upper limit.

Now that explains the error message

No, it doesn't. The error messages are because arrays (pointers) are used when scalars are expected.

Thanks liudr, I used while inside case instead of if..now it works as i expected.. Thanks all for helping me..

AWOL:

Now that explains the error message

No, it doesn’t.
The error messages are because arrays (pointers) are used when scalars are expected.

I just tested it. I guest UL and LL aren’t reserved words and didn’t create a type cast where a variable is needed. So the error message about long int is just from the macro map() taking a pointer and stuffing it into a long int.