Advertisement
mikroavr

keypad_arduino

Feb 23rd, 2022
1,377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. #include <Keypad.h>
  5. #define BINTANG 42
  6. #define PAGAR 35
  7. #define TOMBOL_A 65
  8. #define TOMBOL_B 66
  9. #define TOMBOL_C 67
  10. #define TOMBOL_D 68
  11.  
  12. const byte ROWS = 4; //four rows const
  13. const byte COLS = 4; //three columns
  14.  
  15. char keys[ROWS][COLS] = {
  16.   {1, 2, 3, 'A'},
  17.   {4, 5, 6, 'B'},
  18.   {7, 8, 9, 'C'},
  19.   {'*', '0', '#', 'D'}
  20. };
  21. byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
  22. byte colPins[COLS] = {3, 2, 1, 0}; //connect to the column pinouts of the keypad
  23. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  24. // Set the LCD address to 0x27 for a 16 chars and 2 line display
  25. LiquidCrystal_I2C lcd(0x27, 16, 2);
  26.  
  27. long dtKey = 0;
  28.  
  29. void setup() {
  30.   //Serial.begin(9600);
  31.   lcd.init();
  32.   lcd.backlight();
  33. }
  34. void loop() {
  35.   char key = keypad.getKey();
  36.   if (key) {
  37.     if (key == BINTANG ) { // clear data = tekan *;
  38.       lcd.clear();
  39.       dtKey = 0;
  40.       key = 0;
  41.       lcd.print(dtKey);
  42.     }
  43.     if ( key == 48 )key = 0; // conversi variable '0' ke 0
  44.     lcd.clear();
  45.     dtKey = dtKey * 10 + key;
  46.     lcd.print(dtKey);
  47.   }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement