#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Servo.h>
const byte ROWS = 4;
const byte COLS = 4;
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};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int servoPin = 10;
Servo myServo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int fwdButtonPin = 11; // Deklarasi pin tombol maju
const int revButtonPin = 12; // Deklarasi pin tombol mundur
const int stopButtonPin = 13; // Deklarasi pin tombol stop
int count = 0;
void setup() {
pinMode(servoPin, OUTPUT);
pinMode(fwdButtonPin, INPUT_PULLUP); // Mengatur pin tombol sebagai input dengan resistor pull-up internal
pinMode(revButtonPin, INPUT_PULLUP);
pinMode(stopButtonPin, INPUT_PULLUP);
lcd.begin(16,2);
lcd.backlight();
myServo.attach(servoPin);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
lcd.clear();
lcd.print("Jumlah Barang: ");
lcd.print(key);
count = key - '0';
}
if (digitalRead(fwdButtonPin) == LOW) {
lcd.clear();
lcd.print("Motor Maju");
myServo.write(90);
} else if (digitalRead(revButtonPin) == LOW) {
lcd.clear();
lcd.print("Motor Mundur");
myServo.write(0);
} else if (digitalRead(stopButtonPin) == LOW) {
lcd.clear();
lcd.print("Motor Stop");
myServo.write(45);
}
}