Shekhar777

KEYPAD CODE

Mar 29th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2.  
  3. // initialize the library with the numbers of the interface pins
  4.  
  5. LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//RS,EN,D4,D5,D6,D7
  6.  
  7. #include <Keypad.h>//header for keypad commands enabling
  8.  
  9. const byte ROWS = 4; // Four rows
  10.  
  11. const byte COLS = 4; // Three columns
  12.  
  13. // Define the Keymap
  14.  
  15. char keys[ROWS][COLS] = {
  16.  
  17.   {'1','2','3','A'},
  18.  
  19.   {'4','5','6','B'},
  20.  
  21.   {'7','8','9','C'},
  22.  
  23.   {'#','0','*','D'}
  24.  
  25. };
  26.  
  27. // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
  28.  
  29. byte rowPins[ROWS] = { 0, 1, 2, 3 };
  30.  
  31. // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
  32.  
  33. byte colPins[COLS] = { 4, 5, 6, 7 };
  34.  
  35. //  Create the Keypad
  36.  
  37. Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  38.  
  39. void setup()
  40.  
  41. {
  42.  
  43.   for(int k=8;k<14;k++)
  44.  
  45.   {
  46.  
  47.     pinMode(k,OUTPUT);//pins 8-14 are enabled as output
  48.  
  49.   }
  50.  
  51.   lcd.begin(16, 2);//initializing LCD
  52.  
  53. }
  54.  
  55. void loop()
  56.  
  57. {
  58.  
  59.   char key = kpd.getKey(); //storing pressed key value in a char
  60.  
  61.   if (key != NO_KEY)
  62.  
  63. {
  64.  
  65.       lcd.print(key); //showing pressed character on LCD
  66.  
  67.   }
  68.  
  69. }
Add Comment
Please, Sign In to add comment