//----------------------------------------------//
// DEP.RISET & DEVELOPMENT PT.KMSI //
// PROGRAM WATER MATIC V.02 //
//----------------------------------------------//
//--------------------DONE----------------------//
/* https://drive.google.com/drive/folders/1Ut6DXOjooY1B7jmoPgQ7SmhYUEw3YBXw?usp=sharing */
//==============================================// ULTRASONIK SENSOR
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); // RX, TX
unsigned char data[4] = {};
int distance;
//==============================================// EEPROM
#include <EEPROM.h>
int inputData;
int readData[21];
String numStr;
String passStr;
String newPassword;
String inputPass;
char storedPassword[9];
const byte passwordAddress = 42;
const int maxAttempts = 5;
//==============================================// KEYPAD
#include <Keypad.h>
#define BUP 'A' //-- Up
#define BDN 'B' //-- Down
#define DEL 'C' //-- Delete
#define BOK '*' //-- Ok
#define BCK '#' //-- Back
char key;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'}, // A = UP
{'4', '5', '6', 'B'}, // B = DOWN
{'7', '8', '9', 'C'}, // C = OK
{'*', '0', '#', 'D'} // D = DELETE, # = BACK
};
byte rowPins[ROWS] = {25, 24, 23, 22}; //-- Row connection pin
byte colPins[COLS] = {29, 28, 27, 26}; //-- Coloum connection pin
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//==============================================// LIQUID CRYSTAL
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
//==============================================// TRUCK
//-- Inisialisasi GPIO Tower Lamp Indicator
#define LTRUCK 37
#define L50KL 36
#define L20KL 35
#define LPUMP 34
//-- Inisialisasi GPIO Electrical Water Pump
#define VALVE 33
#define ACC 32
#define START 31
//==============================================// MILLIS TIMER
const byte DelaySetupSensor = 1000; //--delay for setup sensor
const byte Delay = 100; //--millis delay
unsigned long currentMillis; //--for looping
unsigned long currentPassMillis; //--for password
unsigned long currentStarterMillis; //--for crannking
unsigned long currentLedMillis; //--for lamp
unsigned long currentTimeMillis; //--for timer 10 s
unsigned long previousMillis; //--for looping
unsigned long previousPassMillis; //--for password
unsigned long previousStarterMillis; //--for cranking
unsigned long previousLedMillis; //--for lamp
unsigned long startMillis1; //--dispaly pause time when the truck 20KL arrives
unsigned long startMillis2; //--dispaly pause time when the truck 50KL arrives
unsigned long startMillis3; //--dispaly pause time when the truck 20KL leaves
unsigned long startMillis4; //--dispaly pause time when the truck 50KL leaves
unsigned long elapsedSeconds20KL; //--from startMillis1
unsigned long elapsedSeconds50KL; //--from startMillis2
//==============================================// LOGIC
//-- BOOLEAN => FALSE/TRUE
boolean state; //--to run the truck 20/50KL function
boolean mode20KL; //--to run the truck 20KL function
boolean mode50KL; //--to run the truck 20KL function
boolean back; //--to back from input password
//-- INTEGER
int truckChoice; //--to select type of the truck
int count20KL; //--to lamp 20KL
int count50KL; //--to lamp 50KL
int ledState; //--to state blink led
int starterState; //--to state cranking/starter
//==============================================// STORED DATA
const int dataSize = 20; // Total data yang ingin disimpan
int values[dataSize] = {
360, 100,
200, 250, 210, 260, 200, 210,
100, 150, 110, 260, 100, 110,
10, 5,
10, 5,
3, 2,
};
String password;
int distance_UP;
int distance_DOWN;
int distanceA_COME20KL;
int distanceB_COME2OKL;
int distanceA_EMPTY20KL;
int distanceB_EMPTY20KL;
int distanceA_FULL20KL;
int distanceB_FULL20KL;
int distanceA_COME50KL;
int distanceB_COME5OKL;
int distanceA_EMPTY50KL;
int distanceB_EMPTY50KL;
int distanceA_FULL50KL;
int distanceB_FULL50KL;
int delayCOME20KL;
int delayCOME50KL;
int delayFULL20KL;
int delayFULL50KL;
int delayCranking;
int delayLamp;
int failedAttempts;
//==============================================// VOLTAGE DEVIDER
//-- Inisialiasi Voltage Divider (50v max)
int VoltDiv = A0;
float vin = 0.0;
float result = 0.0;
float R1 = 7500.0; //-- Resistor 7.5K
float R2 = 68000.0; //-- Resistor 68K
int value = 0;
const byte crankingValue = 13;
//==============================================// FUNCTION TO RESET
//-- Restart After Setup
void(* reset) (void) = 0;