#include <LiquidCrystal.h>
#include <Keypad.h>
const int ROW_NUM = 4; // jumlah baris pada keypad
const int COLUMN_NUM = 4; // jumlah kolom pada keypad
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pin_rows[ROW_NUM] = {7, 6, 5, 4}; // terhubung dengan pin-pins baris keypad
byte pin_column[COLUMN_NUM] = {3, 2, 1, 0}; // terhubung dengan pin-pins kolom keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // Sesuaikan pin LCD dengan koneksi di Arduino
const float hargaPerLiter = 10000.0; // Harga per liter bensin
float totalBensin = 0.0; // Jumlah total bensin yang dibeli
float totalHarga = 0.0; // Jumlah total harga yang harus dibayar
void setup() {
lcd.begin(16, 2); // Inisialisasi LCD dengan ukuran 16x2
lcd.print("Selamat Datang Di SPBU");
delay(2000);
lcd.clear();
}
void loop() {
char key = keypad.getKey(); // Membaca input dari keypad
if (key) {
if (key == 'A'){
lcd.setCursor(0, 0);
lcd.print("Total: Rp 10000");
lcd.setCursor(0, 1);
lcd.print("Bensin: 1.00 ");
delay(2000);
lcd.clear(); // Membersihkan layar LCD
for (float i=0; i<=10000; i+=50){
lcd.setCursor(0, 0);
lcd.print("Total: Rp ");
lcd.print(i);
lcd.setCursor(0, 1);
lcd.print("bensin ");
lcd.print(totalBensin+=0.005);
delay(50);
}
}
if (key == 'B'){
lcd.setCursor(0, 0);
lcd.print("Total: Rp 20000");
lcd.setCursor(0, 1);
lcd.print("Bensin: 2.00 ");
delay(2000);
lcd.clear(); // Membersihkan layar LCD
for (float i=0; i<=20000; i+=50){
lcd.setCursor(0, 0);
lcd.print("Total: Rp ");
lcd.print(i);
lcd.setCursor(0, 1);
lcd.print("bensin ");
lcd.print(totalBensin+=0.005);
delay(50);
}
}
if (key == 'C'){
lcd.setCursor(0, 0);
lcd.print("Total: Rp 30000");
lcd.setCursor(0, 1);
lcd.print("Bensin: 3.00 ");
delay(2000);
lcd.clear(); // Membersihkan layar LCD
for (float i=0; i<=30000; i+=50){
lcd.setCursor(0, 0);
lcd.print("Total: Rp ");
lcd.print(i);
lcd.setCursor(0, 1);
lcd.print("bensin ");
lcd.print(totalBensin+=0.005);
delay(50);
}
}
if (key == 'D'){
lcd.setCursor(0, 0);
lcd.print("Total: Rp 40000");
lcd.setCursor(0, 1);
lcd.print("Bensin: 4.00 ");
delay(2000);
lcd.clear(); // Membersihkan layar LCD
for (float i=0; i<=40000; i+=50){
lcd.setCursor(0, 0);
lcd.print("Total: Rp ");
lcd.print(i);
lcd.setCursor(0, 1);
lcd.print("bensin ");
lcd.print(totalBensin+=0.005);
delay(50);
}
}
}
delay(1000); // Memberi jeda 0.1 detik (sesuaikan sesuai kebutuhan)
}