#include <EEPROM.h> //library TDS
#include "GravityTDS.h" //library TDS
#include <Wire> //library TDS
#include <LiquidCrystal_I2C.h> //library LCD I2C
#include <Keypad.h> //library Keypad
#define TdsSensorPin A1 //deklarasi TDS
#define relayPin 12 //deklarasi relay
#define BOUNCE 50 //deklarasi delay
GravityTDS gravityTds; //deklarasi delay
int nilaiPPM = 0;
int selectedOption = 0;
char tknTombol = ;
const byte ROWS = 4;
const byte COLS = 4;
const 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[ROWS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.setup();
lcd.backlight();
lcd.begin(16, 2);
pinMode(relayPin, OUTPUT);
displaySplashScreen();
Serial.begin(9600);
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0);
gravityTds.setAdcRange(1024);
gravityTds.backlight();
Serial.begin(115200);
}
void loop() {
gravityTds.setTemperature(temperature);
gravityTds.update();
tdsValue = gravityTds.getTdsValue();
if (tdsValue < nilaiPPM) {
togglePump (true);
} else {
togglePump (false);
}
lcd.setCursor(0, 0);
lcd.print("SMART NUTRITION!");
lcd.setCursor(0, 1);
lcd.print(" (MENU) ");
char key = keypad.getKey();
if (key) {
handleKeypadInput (key);
}
}
void displaySplashScreen() {
lcd.clear();
lcd.setCursor(1, 0);
lcd.print(" HELLO! ");
lcd.setCursor(2, 1);
lcd.print("s a n d l a n z|");
delay(2000);
lcd.clear();
}
void handleKeypadInput(char key) {
switch (key) {
case 'A':
displatTDSValue();
break;
case 'B':
adjustPPMSetting();
break;
}
}
void displatTDSValue() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Setting PPM:");
lcd.print(nilaiPPM);
lcd.setCursor(0, 1);
lcd.print(tdsValue);
lcd.print(" PPM");
delay(5000);
lcd.clear();
}
void adjustPPMSetting() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set PPM:");
lcd.setCursor(0, 1);
lcd.print(nilaiPPM);
whille (true) {
char key = keypad.getKey();
if (key == '*'){
break;
} else if(key == 'D'){
int nilaiPPM = 0;
lcd.setCursor(0, 1);
lcd.print("DATA DIHAPUS");
delay(2000);
break;
} else if(key == '#'){
nilaiPPM = constrain (nilaiPPM,0,9999);
lcd.setCursor(0, 1);
lcd.print("Set ke ");
lcd.print(nilaiPPM;
delay(2000);
break;
} else if (key >= '0' && key <= '9'){
nilaiPPM = nilaiPPM * 10 + (key - '0');
lcd.setCursor(0, 1);
lcd.print(nilaiPPM);
}
}
lcd.clear();
}
void togglePump(bool state) {
if (state) {
digitalWrite(relayPin, HIGH);
} else {
digitalWrite(relayPin, LOW);
}
}