#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#define START_BUTTON_PIN 33
#define STOP_BUTTON_PIN 32
#define RELAY_1_PIN 23
#define RELAY_2_PIN 25
#define RELAY_3_PIN 26
#define RELAY_4_PIN 27
LiquidCrystal_I2C lcd(0x27, 20, 4);
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] = {13, 12, 14, 15};
byte colPins[COLS] = {16, 17, 18, 19};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String inputVolume = "";
int targetVolume = 0;
bool startEnabled = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("FillFlow System");
pinMode(START_BUTTON_PIN, INPUT_PULLUP);
pinMode(STOP_BUTTON_PIN, INPUT_PULLUP);
pinMode(RELAY_1_PIN, OUTPUT);
pinMode(RELAY_2_PIN, OUTPUT);
pinMode(RELAY_3_PIN, OUTPUT);
pinMode(RELAY_4_PIN, OUTPUT);
digitalWrite(RELAY_1_PIN, LOW);
digitalWrite(RELAY_2_PIN, LOW);
digitalWrite(RELAY_3_PIN, LOW);
digitalWrite(RELAY_4_PIN, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
char key = keypad.getKey();
if (key) {
if (key >= '0' && key <= '9') {
inputVolume += key;
lcd.setCursor(0, 1);
lcd.print(inputVolume);
} else if (key == '#') {
targetVolume = inputVolume.toInt();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Volume: ");
lcd.print(targetVolume);
lcd.print(" ml");
} else if (key == '*') {
inputVolume = "";
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter volume:");
}
}
if (digitalRead(START_BUTTON_PIN) == LOW && startEnabled) {
digitalWrite(RELAY_1_PIN, HIGH);
lcd.setCursor(0, 1);
lcd.print("memulai pengisian");
}
delay(10); // this speeds up the simulation
}