Hello Everyone. I wanted to do programming to enter two digit number through keypad and display it on LCD. Also I want to program key 'A' as if it is entered, next number to that key should display on LCD .For example, if I enter 21 number through keypad so when I press key 'A', next number i,e 22 should be displayed on LCD..but i couldnt get ouput for program i have written'...excuse me if I asked any silly question...here is my code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//RS,EN,D4,D5,D6,D7
#include <Keypad.h>//header for keypad commands enabling
const byte ROWS = 4; // Four rows
int i=0;
const byte COLS = 4; // Three colum
int my_key [50]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,40,41,
42,43,44,45,46,47,48,49,50};
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'#','0','*','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 0, 1, 2, 3 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 4, 5, 6, 7 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
for(int k=8;k<14;k++)
{
pinMode(k,OUTPUT);//pins 8-14 are enabled as output
}
lcd.begin(16, 2);//initializing LCD
lcd.print(my_key[i]) ;
int key_event();
}
void loop()
{
}
int key_event()
{
char key = kpd.getKey();
if (key != NO_KEY)
{
i=1;
if (key == 'A' )
{
i=i+1;
lcd.setCursor(0, 1);
lcd.print(my_key[i]) ;
}
else if(key== 'B')
{
i=i-1;
lcd.setCursor(3, 1);
lcd.print(my_key[i-1]);
}
}
}