//--------------------------------- Include Libraries----------------------------------
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "HX711.h" //memasukan library HX711
#include "EEPROM.h"
//--------------------------------- Include Libraries----------------------------------
//--------------------------------- Define and Constant--------------------------------
#define backButton 18 //18
#define selectButton 19 //23
#define selectButton2 2 //2
#define upButton 20 //20
#define downButton 21 //21
volatile boolean backButton_buf = false;
volatile boolean selectButton_buf = false;
volatile boolean selectButton2_buf = false;
volatile boolean upButton_buf = false;
volatile boolean downButton_buf = false;
#define TFT_DC 48
#define TFT_CS 53
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
const int LOADCELL_DOUT_PIN = A0;
const int LOADCELL_SCK_PIN = A1;
const int LOADCELL_DOUT_PIN2 = A2;
const int LOADCELL_SCK_PIN2 = A3;
const int LOADCELL_DOUT_PIN3 = A4;
const int LOADCELL_SCK_PIN3 = A5;
const int LOADCELL_DOUT_PIN4 = A6;
const int LOADCELL_SCK_PIN4 = A7;
HX711 scale; // HX711(DT,SCK)
HX711 scale2;
HX711 scale3;
HX711 scale4;
float calibration_factor, calibration_factor2, calibration_factor3, calibration_factor4;
String heavy, heavy2, heavy3, heavy4;
int sensorStatus, sensorStatus2, sensorStatus3, sensorStatus4;
int IRSensor = 6;
int IRSensor2 = 7;
int IRSensor3 = 8;
int IRSensor4 = 9;
int valvepin = 1;
int valvepin2 = 3;
int valvepin3 = 4;
int valvepin4 = 5;
unsigned long prevMillis = 0;
unsigned long prevMillis2 = 0;
unsigned long prevMillis3 = 0;
unsigned long prevMillis4 = 0;
unsigned long previousMillisCell1 = 0;
unsigned long previousMillisCell2 = 0;
unsigned long previousMillisCell3 = 0;
unsigned long previousMillisCell4 = 0;
//--------------------------------- Define and Constant--------------------------------
//--------------------------------- Global Variable------------------------------------
int menu = 1;
int menu2 = 1;
int menu3 = 1;
int menu4 = 1;
int menucell1 = 1;
int menucell2 = 1;
int menucell3 = 1;
int menucell4 = 1;
int buttonmenu1 = 1;
int buttonmenu2 = 1;
int buttonmenu3 = 1;
int buttonmenu4 = 1;
int buttonauto1 = 1;
bool en_loop1 = true;
bool en_loop2;
bool en_loop3;
bool en_loop4;
bool en_cell1;
bool en_cell2;
bool en_cell3;
bool en_cell4;
String status, status1, status2, status3, status4;
String str, str2, str3, str4;
String texting, texting2, texting3, texting4, texting5, texting6;
String textcall;
String batas, batas2;
String call, call2, call3, call4;
String msg;
String add, add2, add3, add4, add5, add6, add7, add8;
int calibration1, calibration2, calibration3, calibration4;
int factor, factor2, factor3, factor4;
//define the batas 1 dan batas 2 each weigher
int w1_l1, w1_l2, w2_l1, w2_l2, w3_l1, w3_l2, w4_l1, w4_l2;
//add factor can be 1,10,100
int add_factor = 1;
int add_factor2 = 1;
int add_factor3 = 1;
int add_factor4 = 1;
//--------------------------------- Global Variable------------------------------------
//--------------------------------- User Defined Fucntion Stage 1----------------------
void first_upload() {
byte check;
int value = 0;
EEPROM.get(100, check);
if (check == 255) {
EEPROM.put(0, value);
EEPROM.put(2, value);
EEPROM.put(4, value);
EEPROM.put(6, value);
EEPROM.put(8, value);
EEPROM.put(10, value);
EEPROM.put(12, value);
EEPROM.put(14, value);
EEPROM.put(16, value);
EEPROM.put(18, value);
EEPROM.put(20, value);
EEPROM.put(22, value);
EEPROM.put(100, value); //change the value from 255 to 0 so it's only excecuti once after upload
}
}
void Add_Factor() {
add_factor = add_factor + 1;
(add_factor > 100) ? void(add_factor = 1) : void(0);
}
void Add_Factor11() {
add_factor = add_factor - 1;
(add_factor < 0) ? void(add_factor = 1) : void(0);
}
void Add_Factor2() {
add_factor2 = add_factor2 + 1;
(add_factor2 > 100) ? void(add_factor2 = 1) : void(0);
}
void Add_Factor21() {
add_factor2 = add_factor2 - 1;
(add_factor2 < 0) ? void(add_factor2 = 1) : void(0);
}
void Add_Factor3() {
add_factor3 = add_factor3 + 1;
(add_factor3 > 100) ? void(add_factor3 = 1) : void(0);
}
void Add_Factor31() {
add_factor3 = add_factor3 - 1;
(add_factor3 < 0) ? void(add_factor3 = 1) : void(0);
}
void Add_Factor4() {
add_factor4 = add_factor4 + 1;
(add_factor4 > 100) ? void(add_factor4 = 1) : void(0);
}
void Add_Factor41() {
add_factor4 = add_factor4 - 1;
(add_factor4 < 0) ? void(add_factor4 = 1) : void(0);
}
void GetLimit() {
EEPROM.get(0, w1_l1);
EEPROM.get(2, w1_l2);
EEPROM.get(4, w2_l1);
EEPROM.get(6, w2_l2);
EEPROM.get(8, w3_l1);
EEPROM.get(10, w3_l2);
EEPROM.get(12, w4_l1);
EEPROM.get(14, w4_l2);
EEPROM.get(16, calibration1);
EEPROM.get(18, calibration2);
EEPROM.get(20, calibration3);
EEPROM.get(22, calibration4);
}
//--------------------------------- Setup----------------------------------------------
void setup() {
EEPROM.begin();
first_upload();
//Initialize TFT LCD
tft.begin();
Serial.begin(9600);
Serial.println("Memulai program kalibrasi pada sensor berat");
Serial.println("Pastikan tidak ada beban diatas sensor");
delay(5000);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale2.begin(LOADCELL_DOUT_PIN2, LOADCELL_SCK_PIN2);
scale3.begin(LOADCELL_DOUT_PIN3, LOADCELL_SCK_PIN3);
scale4.begin(LOADCELL_DOUT_PIN4, LOADCELL_SCK_PIN4);
pinMode(IRSensor, INPUT);
pinMode(IRSensor2, INPUT);
pinMode(IRSensor3, INPUT);
pinMode(IRSensor4, INPUT);
pinMode(valvepin, OUTPUT);
digitalWrite(valvepin, LOW);
pinMode(valvepin2, OUTPUT);
digitalWrite(valvepin2, LOW);
pinMode(valvepin3, OUTPUT);
digitalWrite(valvepin3, LOW);
pinMode(valvepin4, OUTPUT);
digitalWrite(valvepin4, LOW);
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(selectButton, INPUT_PULLUP);
pinMode(selectButton2, INPUT_PULLUP);
pinMode(backButton, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(backButton), ISR_backButton, FALLING);
attachInterrupt(digitalPinToInterrupt(selectButton), ISR_selectButton, FALLING);
attachInterrupt(digitalPinToInterrupt(selectButton2), ISR_selectButton2, FALLING);
attachInterrupt(digitalPinToInterrupt(upButton), ISR_upButton, FALLING);
attachInterrupt(digitalPinToInterrupt(downButton), ISR_downButton, FALLING);
scale.set_scale();
scale2.set_scale();
scale3.set_scale();
scale4.set_scale();
scale.tare(); // auto zero / mengenolkan pembacaan berat
scale2.tare();
scale3.tare();
scale4.tare();
scale.read_average();
scale2.read_average();
scale3.read_average();
scale4.read_average();
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
updateMenu();
GetLimit();
}
//--------------------------------- Setup----------------------------------------------
//ISR Function
void ISR_backButton() {
backButton_buf = true;
}
void ISR_selectButton() {
selectButton_buf = true;
}
void ISR_selectButton2() {
selectButton2_buf = true;
}
void ISR_upButton() {
upButton_buf = true;
}
void ISR_downButton() {
downButton_buf = true;
}
//--------------------------------- Loop-----------------------------------------------
void loop() {
if (en_loop1) loop1();//First Layer, no issue
if (en_loop2) {
if (buttonauto1 == 2) {
IRSensor = digitalRead(IRSensor);
IRSensor2 = digitalRead(IRSensor2);
IRSensor3 = digitalRead(IRSensor3);
sensorStatus4 = digitalRead(IRSensor4);
if (millis() - prevMillis >= 500) { //instalasi seluruh baca sensor untuk bergerak selama 1 detik
prevMillis = millis();
calibration_factor = EEPROM.get(16, calibration1);
scale.set_scale(calibration_factor);
heavy = String(scale.get_units() / 1000.0);
if (IRSensor == 1) {
if (heavy.toFloat() <= 0) {
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin, LOW);
} else if (heavy.toFloat() >= 1 && heavy.toFloat() <= w1_l1 - 1) {
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print(heavy + "Kg");
digitalWrite(valvepin, HIGH);
} else if (heavy.toFloat() >= w1_l1 && heavy.toFloat() <= w1_l2 - 1) {
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print("GALON 1 BATAS : " + heavy + "Kg");
digitalWrite(valvepin, HIGH);
} else if (heavy.toFloat() <= w1_l2) {
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print("GALON 1 PENUH");
digitalWrite(valvepin, LOW);
} else if (heavy.toFloat() >= w1_l2 + 1) {
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin, LOW);
} else {
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin, LOW);
}
} else {
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin, LOW);
}
}
if (millis() - prevMillis2 >= 500) { //instalasi seluruh baca sensor untuk bergerak selama 1 detik
prevMillis2 = millis();
calibration_factor2 = EEPROM.get(18, calibration2);
scale2.set_scale(calibration_factor2);
heavy2 = String(scale2.get_units() / 1000.0);
if (IRSensor2 == 1) {
if (heavy2.toFloat() <= 0) {
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin2, LOW);
} else if (heavy2.toFloat() >= 1 && heavy2.toFloat() <= w2_l1 - 1) {
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(0, 120 + 20);
tft.print(heavy2 + "Kg");
digitalWrite(valvepin2, HIGH);
} else if (heavy2.toFloat() >= w2_l1 && heavy2.toFloat() <= w2_l2 - 1) {
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print("GALON 2 BATAS : " + heavy2 + "Kg");
digitalWrite(valvepin2, HIGH);
} else if (heavy2.toFloat() <= w2_l2) {
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print("GALON 2 PENUH");
digitalWrite(valvepin2, LOW);
} else if (heavy2.toFloat() >= w2_l2 + 1) {
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin2, LOW);
} else {
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin2, LOW);
}
} else {
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin2, LOW);
}
}
if (millis() - prevMillis3 >= 500) { //instalasi seluruh baca sensor untuk bergerak selama 1 detik
prevMillis3 = millis();
calibration_factor3 = EEPROM.get(20, calibration3);
scale3.set_scale(calibration_factor3);
heavy3 = String(scale3.get_units() / 1000.0);
if (IRSensor3 == 1) {
if (heavy3.toFloat() <= 0) {
tft.fillRect(0, 157, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin3, LOW);
} else if (heavy3.toFloat() >= 1 && heavy3.toFloat() <= w3_l1 - 1) {
tft.fillRect(0, 157, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print(heavy3 + "Kg");
digitalWrite(valvepin3, HIGH);
} else if (heavy3.toFloat() >= w3_l1 && heavy3.toFloat() <= w3_l2 - 1) {
tft.fillRect(0, 157, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print("GALON 3 BATAS : " + heavy3 + "Kg");
digitalWrite(valvepin3, HIGH);
} else if (heavy3.toFloat() <= w3_l2) {
tft.fillRect(0, 157, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print("GALON 3 PENUH");
digitalWrite(valvepin3, LOW);
} else if (heavy3.toFloat() >= w3_l2 + 1) {
tft.fillRect(0, 157, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin3, LOW);
} else {
tft.fillRect(0, 157, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin3, LOW);
}
} else {
tft.fillRect(0, 157, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin3, LOW);
}
}
if (millis() - prevMillis4 >= 500) { //instalasi seluruh baca sensor untuk bergerak selama 1 detik
prevMillis4 = millis();
calibration_factor4 = EEPROM.get(22, calibration4);
scale4.set_scale(calibration_factor4);
heavy4 = String(scale4.get_units() / 1000.0);
if (sensorStatus4 == 1) {
if (heavy4.toFloat() <= 0) {
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin4, LOW);
} else if (heavy4.toFloat() >= 1 && heavy4.toFloat() <= w4_l1 - 1) {
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(0, 180 + 20);
tft.print(heavy4 + "Kg");
digitalWrite(valvepin4, HIGH);
} else if (heavy4.toFloat() >= w4_l1 && heavy4.toFloat() <= w4_l2 - 1) {
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print("GALON 4 BATAS : " + heavy4 + "Kg");
digitalWrite(valvepin4, HIGH);
} else if (heavy4.toFloat() <= w4_l2) {
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.print("GALON 4 PENUH");
digitalWrite(valvepin4, LOW);
} else if (heavy4.toFloat() >= w4_l2 + 1) {
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin4, LOW);
} else {
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin4, LOW);
}
} else {
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin4, LOW);
}
}
}
loop2();
}
if (en_loop3) {
if (buttonmenu1 == 2) {
sensorStatus = digitalRead(IRSensor);
if (millis() - prevMillis >= 500) { //instalasi seluruh baca sensor untuk bergerak selama 1 detik
prevMillis = millis();
calibration_factor = EEPROM.get(16, calibration1);
scale.set_scale(calibration_factor);
heavy = String(scale.get_units() / 1000.0);
if (sensorStatus == 1) {
if (heavy.toFloat() <= 0) {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy + "Kg");
digitalWrite(valvepin, LOW);
} else if (heavy.toFloat() >= 1 && heavy.toFloat() <= w1_l2 - 1) {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy + "Kg");
digitalWrite(valvepin, HIGH);
} else if (heavy.toFloat() >= w1_l2) {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy + "Kg");
digitalWrite(valvepin, LOW);
} else {
digitalWrite(valvepin, LOW);
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy + "Kg");
}
} else {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLUE);
tft.print(heavy + "Kg");
digitalWrite(valvepin, LOW);
}
}
}
if(buttonmenu2 == 2) {
sensorStatus2 = digitalRead(IRSensor2);
if (millis() - prevMillis2 >= 500) { //instalasi seluruh baca sensor untuk bergerak selama 1 detik
prevMillis2 = millis();
calibration_factor2 = EEPROM.get(18, calibration2);
scale2.set_scale(calibration_factor2);
heavy2 = String(scale2.get_units() / 1000.0);
if (sensorStatus2 == 1) {
if (heavy2.toFloat() <= 0) {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy2 + "Kg");
digitalWrite(valvepin2, LOW);
} else if (heavy2.toFloat() >= 1 && heavy2.toFloat() <= w2_l2 - 1) {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy2 + "Kg");
digitalWrite(valvepin2, HIGH);
} else if (heavy2.toFloat() >= w2_l2) {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy2 + "Kg");
digitalWrite(valvepin2, LOW);
} else {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy2 + "Kg");
digitalWrite(valvepin2, LOW);
}
} else {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLUE);
tft.print(heavy2 + "Kg");
digitalWrite(valvepin2, LOW);
}
}
}
if(buttonmenu3 == 2) {
sensorStatus3 = digitalRead(IRSensor3);
if (millis() - prevMillis3 >= 500) { //instalasi seluruh baca sensor untuk bergerak selama 1 detik
prevMillis3 = millis();
calibration_factor3 = EEPROM.get(20, calibration3);
scale3.set_scale(calibration_factor3);
heavy3 = String(scale3.get_units() / 1000.0);
if (sensorStatus3 == 1) {
if (heavy3.toFloat() <= 0) {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy3 + "Kg");
digitalWrite(valvepin3, LOW);
} else if (heavy3.toFloat() >= 1 && heavy3.toFloat() <= w3_l2 - 1) {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy3 + "Kg");
digitalWrite(valvepin3, HIGH);
} else if (heavy3.toFloat() >= w3_l2) {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy3 + "Kg");
digitalWrite(valvepin3, LOW);
} else {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy3 + "Kg");
digitalWrite(valvepin3, LOW);
}
} else {
tft.setCursor(120, 43 + 20);
tft.setTextColor(ILI9341_BLUE);
tft.print(heavy3 + "Kg");
digitalWrite(valvepin3, LOW);
}
}
}
if(buttonmenu4 == 2) {
sensorStatus4 = digitalRead(IRSensor4);
if (millis() - prevMillis4 >= 500) { //instalasi seluruh baca sensor untuk bergerak selama 1 detik
prevMillis4 = millis();
calibration_factor4 = EEPROM.get(22, calibration4);
scale4.set_scale(calibration_factor4);
heavy4 = String(scale4.get_units() / 1000.0);
if (sensorStatus4 == 1) {
if (heavy4.toFloat() <= 0) {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy4 + "Kg");
digitalWrite(valvepin4, LOW);
} else if (heavy4.toFloat() >= 1 && heavy4.toFloat() <= w4_l2 - 1) {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy4 + "Kg");
digitalWrite(valvepin4, HIGH);
} else if (heavy4.toFloat() >= w4_l2) {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy4 + "Kg");
digitalWrite(valvepin4, LOW);
} else {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print(heavy4 + "Kg");
digitalWrite(valvepin4, LOW);
}
} else {
tft.setCursor(120, 143 + 20);
tft.setTextColor(ILI9341_BLUE);
tft.print(heavy4 + "Kg");
digitalWrite(valvepin4, LOW);
}
}
}
loop3();
}
if (en_loop4) loop4();
if (en_cell1) {
if (menucell1 == 3) {
if (millis() - previousMillisCell1 >= 500) {
//kode dibawah ini akan di eksekusi setiap 1 detik setelah en_cell1 enable
previousMillisCell1 = millis();
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
scale.set_scale(add_factor);
heavy = String(scale.get_units() / 1000.0);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_GREEN);
texting3 = "TEXT";
tft.print(texting3);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
call = "<x> : ";
str = add_factor;
calibration1 = add_factor;
texting3 = "> " + call + heavy + "Kg" + " " + str;
tft.print(texting3);
}
}
cell1();
}
if (en_cell2) {
if (menucell2 == 3) {
if (millis() - previousMillisCell2 >= 500) {
//kode dibawah ini akan di eksekusi setiap 1 detik setelah en_cell2 enable
previousMillisCell2 = millis();
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
scale2.set_scale(add_factor2);
heavy2 = String(scale2.get_units() / 1000.0);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_GREEN);
texting4 = "TEXT";
tft.print(texting4);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
call2 = "<x> : ";
str2 = add_factor2;
calibration2 = add_factor2;
texting4 = "> " + call2 + heavy2 + "Kg" + " " + str2;
tft.print(texting4);
}
}
cell2();
}
if (en_cell3) {
if (menucell3 == 3) {
if (millis() - previousMillisCell3 >= 500) {
//kode dibawah ini akan di eksekusi setiap 1 detik setelah en_cell1 enable
previousMillisCell3 = millis();
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
scale3.set_scale(add_factor3);
heavy3 = String(scale3.get_units() / 1000.0);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_GREEN);
texting5 = "TEXT";
tft.print(texting5);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
call3 = "<x> : ";
str3 = add_factor3;
calibration3 = add_factor3;
texting5 = "> " + call3 + heavy3 + "Kg" + " " + str3;
tft.print(texting5);
}
}
cell3();
}
if (en_cell4) {
if (menucell4 == 3) {
if (millis() - previousMillisCell4 >= 500) {
//kode dibawah ini akan di eksekusi setiap 1 detik setelah en_cell1 enable
previousMillisCell4 = millis();
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
scale4.set_scale(add_factor4);
heavy4 = String(scale4.get_units() / 1000.0);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_GREEN);
texting6 = "TEXT";
tft.print(texting6);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
call4 = "<x> :";
str4 = add_factor4;
calibration4 = add_factor4;
texting6 = "> " + call4 + heavy4 + "Kg" + " " + str4;
tft.print(texting6);
}
}
cell4();
}
}
//--------------------------------- Loop-----------------------------------------------
void updateMenu() {
switch (menu) {
case 0:
menu = 1;
break;
case 1:
tft.setTextSize(2);
tft.fillRect(0, 100, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("> AUTOMATIC");
tft.fillRect(0, 150, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 145 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("MANUAL");
tft.fillRect(0, 200, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("CALIBRATION");
break;
case 2:
tft.setTextSize(2);
tft.fillRect(0, 100, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("AUTOMATIC");
tft.fillRect(0, 150, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 145 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("> MANUAL");
tft.fillRect(0, 200, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("CALIBRATION");
break;
case 3:
tft.setTextSize(2);
tft.fillRect(0, 100, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("AUTOMATIC");
tft.fillRect(0, 150, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 145 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("MANUAL");
tft.fillRect(0, 200, 250, 40, ILI9341_GREEN);
tft.setCursor(20, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("> CALIBRATION");
break;
}
en_loop1 = true; //enable loop 1
en_loop2 = false;
en_loop3 = false;
en_loop4 = false;
en_cell1 = false;
en_cell2 = false;
en_cell3 = false;
en_cell4 = false;
}
//--------------------------------- User Defined Fucntion Stage 1----------------------
//--------------------------------- Action for Button Input---------------------------
void executeAction() {
switch (menu) {
case 1: //Automatic only active loop 2
action1();
en_loop1 = false;
en_loop2 = true;
en_loop3 = false;
en_loop4 = false;
en_cell1 = false;
en_cell2 = false;
en_cell3 = false;
en_cell4 = false;
break;
case 2: //manual only active loop 3
action2();
en_loop1 = false;
en_loop2 = false;
en_loop3 = true;
en_loop4 = false;
en_cell1 = false;
en_cell2 = false;
en_cell3 = false;
en_cell4 = false;
break;
case 3: //calibration only active loop 4
action3();
en_loop1 = false;
en_loop2 = false;
en_loop3 = false;
en_loop4 = true;
en_cell1 = false;
en_cell2 = false;
en_cell3 = false;
en_cell4 = false;
break;
}
}
void executeAction2() {
switch (menu4) {
case 1: // only activd cell1
actioncell1();
en_loop1 = false;
en_loop2 = false;
en_loop3 = false;
en_loop4 = false;
en_cell1 = true;
en_cell2 = false;
en_cell3 = false;
en_cell4 = false;
break;
case 2: // only activd cell2
actioncell2();
en_loop1 = false;
en_loop2 = false;
en_loop3 = false;
en_loop4 = false;
en_cell1 = false;
en_cell2 = true;
en_cell3 = false;
en_cell4 = false;
break;
case 3: // only activd cell3
actioncell3();
en_loop1 = false;
en_loop2 = false;
en_loop3 = false;
en_loop4 = false;
en_cell1 = false;
en_cell2 = false;
en_cell3 = true;
en_cell4 = false;
break;
case 4: // only activd cell4
actioncell4();
en_loop1 = false;
en_loop2 = false;
en_loop3 = false;
en_loop4 = false;
en_cell1 = false;
en_cell2 = false;
en_cell3 = false;
en_cell4 = true;
break;
}
}
void action1() {
if(status1 == "on" || status2 == "on" || status3 == "on" || status4 == "on") {
tft.setCursor(10, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print("THE MANUAL IS STILL ACTIVE");
} else {
tft.setCursor(63, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("AUTOMATIC");
switch (buttonauto1) {
case 0:
tft.setTextColor(ILI9341_BLACK);
buttonauto1 = 1;
break;
case 1:
status = "off";
heavy = "0";
heavy2 = "0";
heavy3 = "0";
heavy4 = "0";
scale.power_down();
scale2.power_down();
scale3.power_down();
scale4.power_down();
tft.fillRect(35, 50, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 50, 80, 40, ILI9341_RED);
tft.setCursor(150, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 157 + 20);
tft.fillRect(0, 150, 250, 40, ILI9341_BLACK);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
digitalWrite(valvepin, LOW);
digitalWrite(valvepin2, LOW);
digitalWrite(valvepin3, LOW);
digitalWrite(valvepin4, LOW);
break;
case 2:
scale.power_up();
scale2.power_up();
scale3.power_up();
scale4.power_up();
status = "on";
tft.fillRect(35, 50, 80, 40, ILI9341_RED);
tft.setCursor(65, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 50, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
break;
}
}
}
void action2() {
if(status == "on") {
tft.setCursor(10, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print("AUTOMATIC STILL ON");
} else {
tft.setCursor(84, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("MANUAL");
switch (menu3) {
case 0:
menu3 = 1;
break;
case 1:
switch (buttonmenu1) {
case 0:
buttonmenu1 = 1;
break;
case 1:
status1 = "off";
scale.power_down();
tft.fillRect(35, 50, 169, 40, ILI9341_BLUE);
tft.setCursor(83, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 1");
tft.fillRect(35, 100, 80, 40, ILI9341_GREEN);
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(65, 93 + 20);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_RED);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
digitalWrite(valvepin, LOW);
break;
case 2:
status1 = "on";
scale.power_up();
tft.fillRect(35, 50, 169, 40, ILI9341_BLUE);
tft.setCursor(0, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 1");
tft.fillRect(35, 100, 80, 40, ILI9341_RED);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
break;
}
if (status2 == "off") {
tft.fillRect(35, 150, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 2");
tft.fillRect(35, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_RED);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
digitalWrite(valvepin2, LOW);
} else if (status2 == "on") {
tft.fillRect(35, 150, 169, 40, ILI9341_GREEN);
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(83, 143 + 20);
tft.print("VALVE 2");
tft.fillRect(35, 200, 80, 40, ILI9341_RED);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
} else {
tft.fillRect(35, 150, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 2");
tft.fillRect(35, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_RED);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
}
break;
case 2:
if (status1 == "off") {
tft.fillRect(35, 50, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 1");
tft.fillRect(35, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_RED);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
} else if (status1 == "on") {
tft.fillRect(35, 50, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 1");
tft.fillRect(35, 100, 80, 40, ILI9341_RED);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
} else {
tft.fillRect(35, 50, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 1");
tft.fillRect(35, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_RED);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
}
switch (buttonmenu2) {
case 0:
buttonmenu2 = 1;
break;
case 1:
status2 = "off";
scale2.power_down();
tft.fillRect(35, 150, 169, 40, ILI9341_BLUE);
tft.setCursor(83, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 2");
tft.fillRect(35, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_RED);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
digitalWrite(valvepin2, LOW);
break;
case 2:
status2 = "on";
scale2.power_up();
tft.fillRect(35, 150, 169, 40, ILI9341_BLUE);
tft.setCursor(0, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 2");
tft.fillRect(35, 200, 80, 40, ILI9341_RED);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
break;
}
break;
case 3:
switch (buttonmenu3) {
case 0:
buttonmenu3 = 1;
break;
case 1:
status3 = "off";
scale3.power_down();
tft.fillRect(35, 50, 169, 40, ILI9341_BLUE);
tft.setCursor(83, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 3");
tft.fillRect(35, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_RED);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
digitalWrite(valvepin3, LOW);
break;
case 2:
status3 = "on";
scale3.power_up();
tft.fillRect(35, 50, 169, 40, ILI9341_BLUE);
tft.setCursor(0, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 3");
tft.fillRect(35, 100, 80, 40, ILI9341_RED);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
break;
}
if (status4 == "off") {
tft.fillRect(35, 150, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 4");
tft.fillRect(35, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_RED);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
} else if (status4 == "on") {
tft.fillRect(35, 150, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 4");
tft.fillRect(35, 200, 80, 40, ILI9341_RED);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
} else {
tft.fillRect(35, 150, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 4");
tft.fillRect(35, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_RED);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
}
break;
case 4:
if (status3 == "off") {
tft.fillRect(35, 50, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 3");
tft.fillRect(35, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_RED);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
} else if (status3 == "on") {
tft.fillRect(35, 50, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 3");
tft.fillRect(35, 100, 80, 40, ILI9341_RED);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
} else {
tft.fillRect(35, 50, 169, 40, ILI9341_GREEN);
tft.setCursor(83, 43 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 3");
tft.fillRect(35, 100, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 100, 80, 40, ILI9341_RED);
tft.setCursor(150, 93 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
}
switch (buttonmenu4) {
case 0:
tft.setTextColor(ILI9341_BLACK);
buttonmenu4 = 1;
break;
case 1:
status4 = "off";
scale4.power_down();
tft.fillRect(35, 150, 169, 40, ILI9341_BLUE);
tft.setCursor(83, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 4");
tft.fillRect(35, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_RED);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
digitalWrite(valvepin4, LOW);
break;
case 2:
status4 = "on";
scale4.power_up();
tft.fillRect(35, 150, 169, 40, ILI9341_BLUE);
tft.setCursor(0, 143 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("VALVE 4");
tft.fillRect(35, 200, 80, 40, ILI9341_RED);
tft.setCursor(65, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
tft.fillRect(124, 200, 80, 40, ILI9341_GREEN);
tft.setCursor(150, 193 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
break;
}
break;
}
}
}
void action3() {
if(status == "on") {
tft.setCursor(10, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print("AUTOMATIC STILL ON");
} else if (status1 == "on" || status2 == "on" || status3 == "on" || status4 == "on") {
tft.setCursor(10, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print("MANUALS STILL ON");
} else {
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("CALIBRATION");
switch (menu4) {
case 0:
menu4 = 1;
break;
case 1:
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("> TIMBANGAN 1");
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 2");
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 3");
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 4");
break;
case 2:
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 1");
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("> TIMBANGAN 2");
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 3");
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 4");
break;
case 3:
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 1");
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 2");
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("> TIMBANGAN 3");
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 4");
break;
case 4:
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 1");
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 2");
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("TIMBANGAN 3");
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("> TIMBANGAN 4");
break;
}
}
}
void actioncell1() {
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("TIMBANGAN 1");
switch (menucell1) {
case 0:
menucell1 = 1;
break;
case 1:
scale.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
batas = "BATAS 1 :";
texting = batas + " " + String(w1_l1) + "Kg";
tft.print("> " + texting);
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w1_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration1 == 0) {
call = "<x> :";
str = calibration1;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration1;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor == 0) {
add = "Add Factor :";
add2 = add + " " + "1";
tft.print(add2);
} else {
tft.print(add2);
}
break;
case 2:
scale.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w1_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + String(w1_l2) + "Kg";
tft.print("> " + texting2);
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration1 == 0) {
call = "<x> :";
str = calibration1;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration1;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor == 0) {
add = "Add Factor :";
add2 = add + " " + "1";
tft.print(add2);
} else {
tft.print(add2);
}
break;
case 3:
scale.power_up();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w1_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w1_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor == 0) {
add = "Add Factor :";
add2 = add + " " + "1";
tft.print(add2);
} else {
tft.print(add2);
}
break;
case 4:
scale.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w1_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w1_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration1 == 0) {
call = "<x> :";
str = calibration1;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration1;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
add = "Add Factor :";
factor = add_factor;
add2 = add + " " + String(add_factor);
tft.print("> " + add2);
break;
}
}//menucell1
void actioncell2() {
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("TIMBANGAN 2");
switch (menucell2) {
case 0:
menucell2 = 1;
break;
case 1:
scale2.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
batas = "BATAS 1 :";
texting = batas + " " + String(w2_l1) + "Kg";
tft.print("> " + texting);
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w2_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration2 == 0) {
call = "<x> :";
str = calibration2;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration2;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor2 == 0) {
add3 = "Add Factor :";
add4 = add3 + " " + "1";
tft.print(add4);
} else {
tft.print(add4);
}
break;
case 2:
scale2.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w2_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + String(w2_l2) + "Kg";
tft.print("> " + texting2);
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration2 == 0) {
call = "<x> :";
str = calibration2;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration2;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor2 == 0) {
add3 = "Add Factor :";
add4 = add3 + " " + "1";
tft.print(add4);
} else {
tft.print(add4);
}
break;
case 3:
scale2.power_up();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w2_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w2_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor2 == 0) {
add3 = "Add Factor :";
add4 = add3 + " " + "1";
tft.print(add4);
} else {
tft.print(add4);
}
break;
case 4:
scale2.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w2_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w2_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration2 == 0) {
call = "<x> :";
str = calibration2;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration2;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
add3 = "Add Factor :";
factor2 = add_factor2;
add4 = add3 + " " + String(add_factor2);
tft.print("> " + add4);
break;
}
}//menucell2
void actioncell3() {
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("TIMBANGAN 3");
switch (menucell3) {
case 0:
menucell3 = 1;
break;
case 1:
scale3.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
batas = "BATAS 1 :";
texting = batas + " " + String(w3_l1) + "Kg";
tft.print("> " + texting);
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w3_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration3 == 0) {
call = "<x> :";
str = calibration3;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration3;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor3 == 0) {
add5 = "Add Factor :";
add6 = add5 + " " + "1";
tft.print(add6);
} else {
tft.print(add6);
}
break;
case 2:
scale3.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w3_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + String(w3_l2) + "Kg";
tft.print("> " + texting2);
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration3 == 0) {
call = "<x> :";
str = calibration3;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration3;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor3 == 0) {
add5 = "Add Factor :";
add6 = add5 + " " + "1";
tft.print(add6);
} else {
tft.print(add6);
}
break;
case 3:
scale3.power_up();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w3_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w3_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor3 == 0) {
add5 = "Add Factor :";
add6 = add5 + " " + "1";
tft.print(add6);
} else {
tft.print(add6);
}
break;
case 4:
scale3.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w3_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w3_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration3 == 0) {
call = "<x> :";
str = calibration3;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration3;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
add5 = "Add Factor :";
factor3 = add_factor3;
add6 = add5 + " " + String(add_factor3);
tft.print("> " + add6);
break;
}
}//menucell3
void actioncell4() {
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("TIMBANGAN 4");
switch (menucell4) {
case 0:
menucell4 = 1;
break;
case 1:
scale4.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
batas = "BATAS 1 :";
texting = batas + " " + String(w4_l1) + "Kg";
tft.print("> " + texting);
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w4_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration4 == 0) {
call = "<x> :";
str = calibration4;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration4;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor4 == 0) {
add7 = "Add Factor :";
add8 = add7 + " " + "1";
tft.print(add8);
} else {
tft.print(add8);
}
break;
case 2:
scale4.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w4_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + String(w4_l2) + "Kg";
tft.print("> " + texting2);
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration4 == 0) {
call = "<x> :";
str = calibration4;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration4;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor4 == 0) {
add7 = "Add Factor :";
add8 = add7 + " " + "1";
tft.print(add8);
} else {
tft.print(add8);
}
break;
case 3:
scale4.power_up();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w4_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w4_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
if (factor4 == 0) {
add7 = "Add Factor :";
add8 = add7 + " " + "1";
tft.print(add8);
} else {
tft.print(add8);
}
break;
case 4:
scale4.power_down();
tft.fillRect(0, 55, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 50 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w4_l1 == 0) {
batas = "BATAS 1 :";
texting = batas + " " + "0" + "Kg";
tft.print(texting);
} else {
tft.print(texting);
}
tft.fillRect(0, 105, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 100 + 20);
tft.setTextColor(ILI9341_BLACK);
if (w4_l2 == 0) {
batas2 = "BATAS 2 :";
texting2 = batas2 + " " + "0" + "Kg";
tft.print(texting2);
} else {
tft.print(texting2);
}
tft.fillRect(0, 155, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 150 + 20);
tft.setTextColor(ILI9341_BLACK);
if (calibration4 == 0) {
call = "<x> :";
str = calibration4;
textcall = call + " " + str;
tft.print(textcall);
} else {
textcall = "<x> :";
str = calibration4;
textcall = call + " " + str;
tft.print(textcall);
}
tft.fillRect(0, 205, 250, 40, ILI9341_GREEN);
tft.setCursor(10, 200 + 20);
tft.setTextColor(ILI9341_BLACK);
add7 = "Add Factor :";
factor4 = add_factor4;
add8 = add7 + " " + String(add_factor4);
tft.print("> " + add8);
break;
}
}//menucell14
//--------------------------------- Action for Button Input---------------------------
//--------------------------- Get Button State and Call Action-----------------------------------------
void loop1() {
if (downButton_buf) {
menu++;
if ((menucell1 == 0) || (menu == 4)) menu = 1;
updateMenu();
downButton_buf = false;
}
if (upButton_buf) {
menu--;
if ((menu == 0) || (menu == 3)) menu = 3;
updateMenu();
upButton_buf = false;
}
if (selectButton_buf) {
tft.fillRect(0, 100, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 150, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 200, 250, 40, ILI9341_BLACK);
executeAction();
selectButton_buf = false;
}
}//menu, menucell1,updateMenu(),executeAction()
void loop2() {
if (selectButton_buf) {
buttonauto1++;
if ((buttonauto1 == 0) || (buttonauto1 == 3)) buttonauto1 = 1;
action1();
selectButton_buf = false;
}
if (backButton_buf) {
tft.fillRect(0, 0, 250, 40, ILI9341_BLACK);
tft.setCursor(63, 0 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(35, 50, 80, 40, ILI9341_BLACK);
tft.fillRect(124, 50, 80, 40, ILI9341_BLACK);
tft.fillRect(0, 97, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 90 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 127, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 120 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.setCursor(0, 157 + 20);
tft.fillRect(0, 150, 250, 40, ILI9341_BLACK);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 187, 250, 40, ILI9341_BLACK);
tft.setCursor(0, 180 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
en_loop1 = true;
en_loop2 = false; // very important to disable after excecute
updateMenu();
backButton_buf = false;
}
}//control buttonauto1 dan action 1
void loop3() {
if (downButton_buf) {
menu3++;
if ((menu3 == 0) || (menu3 == 5)) menu3 = 1;
action2();
downButton_buf = false;
}
if (upButton_buf) {
menu3--;
if ((menu3 == 0) || (menu3 == 4)) menu3 = 4;
action2();
upButton_buf = false;
}
if (selectButton_buf) {
(menu3 == 1) ? void(buttonmenu1++) : void (0);
if ((buttonmenu1 == 0) || (buttonmenu1 == 3)) buttonmenu1 = 1;
(menu3 == 2) ? void(buttonmenu2++) : void (0);
if ((buttonmenu2 == 0) || (buttonmenu2 == 3)) buttonmenu2 = 1;
(menu3 == 3) ? void(buttonmenu3++) : void (0);
if ((buttonmenu3 == 0) || (buttonmenu3 == 3)) buttonmenu3 = 1;
(menu3 == 4) ? void(buttonmenu4++) : void (0);
if ((buttonmenu4 == 0) || (buttonmenu4 == 3)) buttonmenu4 = 1;
action2();
selectButton_buf = false;
}
if (backButton_buf) {
tft.fillRect(0, 0, 250, 40, ILI9341_BLACK);
tft.setCursor(84, 0 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(35, 50, 169, 40, ILI9341_BLACK);
tft.fillRect(35, 100, 80, 40, ILI9341_BLACK);
tft.fillRect(124, 100, 80, 40, ILI9341_BLACK);
tft.fillRect(35, 150, 169, 40, ILI9341_BLACK);
tft.fillRect(35, 200, 80, 40, ILI9341_BLACK);
tft.fillRect(124, 200, 80, 40, ILI9341_BLACK);
en_loop1 = true;
en_loop3 = false;
updateMenu();
backButton_buf = false;
}
}//control menu 3 dan action 2
void loop4() {
if (downButton_buf) {
menu4++;
if ((menu4 == 0) || (menu4 == 6)) menu4 = 1;
action3();
downButton_buf = false;
}
if (upButton_buf) {
menu4--;
if ((menu4 == 0) || (menu4 == 5)) menu4 = 5;
action3();
upButton_buf = false;
}
if (selectButton_buf) {
tft.fillRect(0, 0, 250, 40, ILI9341_BLACK);
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 55, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 105, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 155, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 205, 250, 40, ILI9341_BLACK);
executeAction2();
selectButton_buf = false;
}
if (backButton_buf) {
tft.fillRect(0, 0, 250, 40, ILI9341_BLACK);
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 55, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 105, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 155, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 205, 250, 40, ILI9341_BLACK);
en_loop1 = true;
en_loop4 = false;
updateMenu();
backButton_buf = false;
}
}//control menu 4 dan action 3
void cell1() {
if (downButton_buf) {
menucell1++;
if ((menucell1 == 0) || (menucell1 == 5)) menucell1 = 1;
actioncell1();
downButton_buf = false;
}
if (upButton_buf) {
menucell1--;
if ((menucell1 == 0) || (menucell1 == 4)) menucell1 = 4;
actioncell1();
upButton_buf = false;
}
if (backButton_buf) {
tft.fillRect(0, 0, 250, 40, ILI9341_BLACK);
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 55, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 105, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 155, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 205, 250, 40, ILI9341_BLACK);
scale.power_down();
en_loop4 = true;
en_cell1 = false;
menucell1 = 2;
action3();
backButton_buf = false;
}
if (selectButton_buf) {
(menucell1 == 1) ? void(EEPROM.put(0, w1_l1 + (add_factor))) : void (0);
(menucell1 == 2) ? void(EEPROM.put(2, w1_l2 + (add_factor))) : void (0);
(menucell1 == 3) ? void(EEPROM.put(16, calibration1)) : void(0);
(menucell1 == 4) ? Add_Factor() : void (0);
GetLimit();
actioncell1();
selectButton_buf = false;
}
if (selectButton2_buf) {
(menucell1 == 1) ? void(EEPROM.put(0, w1_l1 - (add_factor))) : void (0);
(menucell1 == 2) ? void(EEPROM.put(2, w1_l2 - (add_factor))) : void (0);
(menucell1 == 4) ? Add_Factor11() : void (0);
GetLimit();
actioncell1();
selectButton2_buf = false;
}
}//control menucell1
void cell2() {
if (downButton_buf) {
menucell2++;
if ((menucell2 == 0) || (menucell2 == 5)) menucell2 = 1;
actioncell2();
downButton_buf = false;
}
if (upButton_buf) {
menucell2--;
if ((menucell2 == 0) || (menucell2 == 4)) menucell2 = 4;
actioncell2();
upButton_buf = false;
}
if (backButton_buf) {
tft.fillRect(0, 0, 250, 40, ILI9341_BLACK);
tft.setCursor(53, 0 + 20);
tft.print("text");
tft.setTextColor(ILI9341_BLACK);
tft.fillRect(0, 55, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 105, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 155, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 205, 250, 40, ILI9341_BLACK);
scale2.power_down();
en_loop4 = true;
en_cell2 = false;
action3();
backButton_buf = false;
}
if (selectButton_buf) {
(menucell2 == 1) ? void(EEPROM.put(4, w2_l1 + (add_factor2))) : void (0);
(menucell2 == 2) ? void(EEPROM.put(6, w2_l2 + (add_factor2))) : void (0);
(menucell2 == 3) ? void(EEPROM.put(18, calibration2)) : void(0);
(menucell2 == 4) ? Add_Factor2() : void (0);
GetLimit();
actioncell2();
selectButton_buf = false;
}
if (selectButton2_buf) {
(menucell2 == 1) ? void(EEPROM.put(4, w2_l1 - (add_factor2))) : void (0);
(menucell2 == 2) ? void(EEPROM.put(6, w2_l2 - (add_factor2))) : void (0);
(menucell2 == 4) ? Add_Factor21() : void (0);
GetLimit();
actioncell2();
selectButton2_buf = false;
}
}//control menucell2
void cell3() {
if (downButton_buf) {
menucell3++;
if ((menucell3 == 0) || (menucell3 == 5)) menucell3 = 1;
actioncell3();
downButton_buf = false;
}
if (upButton_buf) {
menucell3--;
if ((menucell3 == 0) || (menucell3 == 4)) menucell3 = 4;
actioncell3();
upButton_buf = false;
}
if (backButton_buf) {
tft.fillRect(0, 0, 250, 40, ILI9341_BLACK);
tft.setCursor(53, 0 + 20);
tft.print("text");
tft.setTextColor(ILI9341_BLACK);
tft.fillRect(0, 55, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 105, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 155, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 205, 250, 40, ILI9341_BLACK);
scale3.power_down();
en_loop4 = true;
en_cell3 = false;
action3();
backButton_buf = false;
}
if (selectButton_buf) {
(menucell3 == 1) ? void(EEPROM.put(8, w3_l1 + (add_factor3))) : void (0);
(menucell3 == 2) ? void(EEPROM.put(10, w3_l2 + (add_factor3))) : void (0);
(menucell3 == 3) ? void(EEPROM.put(20, calibration3)) : void(0);
(menucell3 == 4) ? Add_Factor3() : void (0);
GetLimit();
actioncell3();
selectButton_buf = false;
}
if (selectButton2_buf) {
(menucell3 == 1) ? void(EEPROM.put(8, w3_l1 - (add_factor3))) : void (0);
(menucell3 == 2) ? void(EEPROM.put(10, w3_l2 - (add_factor3))) : void (0);
(menucell3 == 4) ? Add_Factor31() : void (0);
GetLimit();
actioncell3();
selectButton2_buf = false;
}
}//control menucell3
void cell4() {
if (downButton_buf) {
menucell4++;
if ((menucell4 == 0) || (menucell4 == 5)) menucell4 = 1;
actioncell4();
downButton_buf = false;
}
if (upButton_buf) {
menucell4--;
if ((menucell4 == 0) || (menucell4 == 4)) menucell4 = 4;
actioncell4();
upButton_buf = false;
}
if (backButton_buf) {
tft.fillRect(0, 0, 250, 40, ILI9341_BLACK);
tft.setCursor(53, 0 + 20);
tft.setTextColor(ILI9341_BLACK);
tft.print("text");
tft.fillRect(0, 55, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 105, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 155, 250, 40, ILI9341_BLACK);
tft.fillRect(0, 205, 250, 40, ILI9341_BLACK);
scale4.power_down();
en_loop4 = true;
en_cell4 = false;
action3();
backButton_buf = false;
}
if (selectButton_buf) {
(menucell4 == 1) ? void(EEPROM.put(12, w4_l1 + (add_factor4))) : void (0);
(menucell4 == 2) ? void(EEPROM.put(14, w4_l2 + (add_factor4))) : void (0);
(menucell4 == 3) ? void(EEPROM.put(22, calibration4)) : void(0);
(menucell4 == 4) ? Add_Factor4() : void (0);
GetLimit();
actioncell4();
selectButton_buf = false;
}
if (selectButton2_buf) {
(menucell4 == 1) ? void(EEPROM.put(12, w4_l1 - (add_factor4))) : void (0);
(menucell4 == 2) ? void(EEPROM.put(14, w4_l2 - (add_factor4))) : void (0);
(menucell4 == 4) ? Add_Factor41() : void (0);
GetLimit();
actioncell4();
selectButton2_buf = false;
}
}//control menucell3
//--------------------------- Get Button State and Call Action-----------------------------------------
//--------------------------------- Note-----------------------------------------------
/*
*/
//--------------------------------- Note-----------------------------------------------