//#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const byte ROWS = 4; // Jumlah baris pada keypad
const byte COLS = 4; // Jumlah kolom pada keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // Pin-row keypad yang terhubung ke pin digital Arduino
byte colPins[COLS] = {5, 4, 3, 2}; // Pin-kolom keypad yang terhubung ke pin digital Arduino
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 20, 4); // Alamat I2C LCD dan ukuran (20x4)
int literCount = 0; // Variabel untuk menghitung jumlah liter yang dipompa
void setup() {
Serial.begin(9600); // Inisialisasi komunikasi serial
lcd.init(); // Inisialisasi LCD
lcd.backlight(); // Nyalakan backlight LCD
lcd.setCursor(0, 0); // Posisi kursor ke kolom 0, baris 0
lcd.print("[ Pom Mini ]");
lcd.setCursor(0, 1);
lcd.print("Masukkan nilai.. ");
}
void loop() {
char key = keypad.getKey(); // Baca tombol yang ditekan pada keypad
if (key != NO_KEY) { // Jika tombol ditekan
if (key == 'A') { // Jika tombol A (pompa on)
digitalWrite(13, HIGH); // Hidupkan pompa
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pompa ON");
Serial.println("Pompa ON");
} else if (key == 'B') { // Jika tombol B (pompa off)
digitalWrite(13, LOW); // Matikan pompa
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pompa OFF");
Serial.println("Pompa OFF");
} else if (key == 'C') { // Jika tombol C (reset liter count)
literCount = 0; // Reset hitungan liter
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hitungan direset");
Serial.println("Hitungan direset");
} else if (key == 'D') { // Jika tombol D (tampilkan liter count)
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mengisi ");
lcd.print(literCount);
lcd.print(" Liter");
Serial.print("Jumlah Liter: ");
Serial.println(literCount);
} else { // Jika tombol angka (pompa liter)
literCount += (key - '0'); // Tambahkan jumlah liter
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pompa ");
lcd.print(key);
lcd.print(" Liter");
Serial.print("Pompa ");
Serial.print(key);
Serial.println(" Liter");
}
}
delay(100); // Beri sedikit delay untuk stabilitas
}