#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keypad.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define start 5
#define stop 4
#define reset 2
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '.', 'D'}
};
byte rowPins[4] = {12, 16, 17, 13};
byte colPins[4] = {14, 27, 26, 25};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
const unsigned char logo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe3, 0x80, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x40, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x1f, 0xff, 0xe0, 0x00, 0x00, 0x02, 0x7c, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x00, 0x00, 0x07, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0x9e, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x86, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xcf, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x82, 0x00, 0x00, 0x3e, 0x01, 0xf0, 0x00, 0x00, 0x07, 0xe7, 0x80, 0x00,
0x00, 0x00, 0x30, 0x01, 0x93, 0x00, 0x00, 0x3c, 0x30, 0xf0, 0x00, 0x00, 0x73, 0xf3, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x9b, 0x00, 0x00, 0x3d, 0xfe, 0xf0, 0x00, 0x00, 0x7b, 0xf8, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x9b, 0x00, 0x00, 0x3f, 0x87, 0xf0, 0x00, 0x00, 0x3f, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x93, 0x00, 0x00, 0x3e, 0x01, 0xf0, 0x00, 0x03, 0x1f, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x82, 0x00, 0x00, 0x1f, 0xff, 0xe0, 0x00, 0x07, 0x9f, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x86, 0x00, 0x00, 0x1f, 0xff, 0xe0, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x1f, 0x87, 0xe0, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x0f, 0xff, 0xc0, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x8a, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x6f, 0xbe, 0xcc, 0xba, 0xfd, 0xca, 0xaf, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3a, 0xbc, 0x82, 0xd2, 0x35, 0xcc, 0xaa, 0xc8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x6a, 0xbc, 0xce, 0xd2, 0x2d, 0xc8, 0xea, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0c, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x21, 0x00, 0x00, 0x04, 0x20, 0x40, 0x00, 0x00, 0x13, 0x00, 0x00, 0x0c, 0x44, 0x00, 0x00,
0x00, 0x29, 0xbd, 0x78, 0x07, 0x37, 0x7f, 0x77, 0xe0, 0x1b, 0x6b, 0xc0, 0x05, 0xdd, 0x80, 0x00,
0x00, 0x5d, 0x5b, 0x68, 0x04, 0xb6, 0x57, 0x77, 0x20, 0x19, 0x7a, 0xc0, 0x0f, 0xd5, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
byte panjang, lebar;
int16_t x, y;
uint16_t w, h;
int halaman = 1;
int menuItem = 1;
int menuItemDosage = 1;
int menuItemFlowrate = 1;
boolean statusBtnUp = false;
boolean statusBtnOk = false;
boolean statusBtnDown = false;
boolean statusBtnBack = false;
boolean statusBtnBintang = false;
boolean statusBtnStart = false;
boolean statusBtnStop = false;
boolean statusAkhirBtnUp = false;
boolean statusAkhirBtnOk = false;
boolean statusAkhirBtnDown = false;
boolean statusAkhirBtnBack = false;
boolean statusAkhirBtnBintang = false;
boolean statusAkhirBtnStart = false;
boolean statusAkhirBtnStop = false;
boolean UP = false;
boolean OK = false;
boolean DOWN = false;
boolean BACK = false;
boolean BINTANG = false;
boolean confirm = false;
boolean startstatus = false;
boolean stopstatus = false;
String satuanCairan = "ml";
String nilaiCairansisa = "50";
String nilaiCairanused = "1000";
String satuanFlowrate = "ml/h";
float dosage;
float flowrate;
float valueflowrateFeature;
int tampung = 0;
int patokDosageFeature = 0;
String valueKeypad;
String uhuy;
String ihiy;
// MOTOR STEPPER
const int dirPin = 15;
const int stepPin = 0;
int p = 0;
// float konstanta = 0.004219;
float konstanta = 240;
float inject;
float tampungAmount = 50;
void setup() {
Serial.begin(9600);
pinMode(start, INPUT_PULLUP);
pinMode(stop, INPUT_PULLUP);
pinMode(reset, INPUT_PULLUP);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
// pinMode(stop, INPUT_PULLUP);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.drawBitmap(0, 0, logo, 128, 64, 1);
display.display();
delay(1000);
display.clearDisplay();
display.display();
}
void loop() {
statusBtnStart = digitalRead(start);
boolean statusrst = digitalRead(reset);
char customKey = customKeypad.getKey();
bacaKeypad(customKey);
tampilMenu();
// Serial.println("Sekarang Halaman: ");
// Serial.println(halaman);
if (BINTANG && halaman == 1) {
BINTANG = false;
// halaman--;
// if(halaman < 1) {
halaman = 3;
// }
} else if (BINTANG && halaman == 3) {
BINTANG = false;
// halaman++;
// if (halaman >1)halaman = 1;
halaman = 1;
} else {
// untuk button up
if (UP && halaman == 1) {
UP = false;
menuItem --;
if (menuItem < 1)menuItem = 3;
}
//untuk button down
if (DOWN && halaman == 1) {
DOWN = false;
menuItem ++;
if (menuItem > 3) menuItem = 1;
}
// untuk button ok
if (OK) {
OK = false;
if (halaman == 1 && menuItem == 1) {
halaman = 2;
} else if (halaman == 1 && menuItem == 2) {
halaman = 4;
} else if (halaman == 1 && menuItem == 3 && inject != 0) {
halaman = 5;
}
}
// untuk button back
if (BACK) {
BACK = false;
if (halaman == 2 || halaman == 4) {
halaman = 1;
patokDosageFeature = 0;
Serial.println("MASAK MASUK SINI???????????");
}
}
if (!statusrst) {
dosage = 0;
flowrate = 0;
valueKeypad = "";
uhuy = "";
ihiy = "";
valueflowrateFeature = 0;
display.clearDisplay();
display.display();
}
// Serial.println(menuItem);
// delay(100);
}
}
void bacaKeypad(char key) {
if (key) {
// Serial.println(key);
if (key == 'A' || key == 'B' || key == 'C' || key == 'D' || key == '*' ) {
// Serial.println("Tombol Konfirmasi Ditekan = ");
// Serial.println(key);
if (key == 'A') { // UP
// Serial.println("PERGANTIAN TRUE BUTTON UP");
// delay(1000);
statusBtnUp = true;
if (statusBtnUp != statusAkhirBtnUp) {
if (statusBtnUp == 1) {
UP = true;
}
statusBtnUp = false;
}
statusAkhirBtnUp = statusBtnUp;
} else if (key == 'B') { // DOWN
statusBtnDown = true;
if (statusBtnDown != statusAkhirBtnDown) {
if (statusBtnDown == 1) {
DOWN = true;
}
statusBtnDown = false;
}
statusAkhirBtnDown = statusBtnDown;
} else if (key == 'D') { // BACK
statusBtnBack = true;
if (statusBtnBack != statusAkhirBtnBack) {
if (statusBtnBack == 1) {
BACK = true;
}
statusBtnBack = false;
}
statusAkhirBtnBack = statusBtnBack;
} else if (key == 'C') { // UP
statusBtnOk = true;
if (statusBtnOk != statusAkhirBtnOk) {
if (statusBtnOk == 1) {
OK = true;
}
statusBtnOk = false;
}
statusAkhirBtnOk = statusBtnOk;
} else if (key == '*') {
statusBtnBintang = true;
if (statusBtnBintang != statusAkhirBtnBintang) {
if (statusBtnBintang == 1) {
BINTANG = true;
}
statusBtnBintang = false;
}
statusAkhirBtnBintang = statusBtnBintang;
}
} else {
// Serial.println("Tombol Angka / Tidak Ditekan = ");
// Serial.println(key);
if (halaman == 1) {
// Serial.println("Mohon Maaf Tidak Bisa Pake Angka Dihalaman Ini");
} else if (halaman == 2) {
if (patokDosageFeature == 1) {
String konversi = String(key);
uhuy += konversi;
dosage = uhuy.toFloat();
} else if (patokDosageFeature == 2) {
String konversi = String(key);
ihiy += konversi;
flowrate = ihiy.toFloat();
} else {
// Serial.println("KONDISI TIDAK DIEDIT");
}
} else {
String konversi = String(key);
valueKeypad += konversi;
valueflowrateFeature = valueKeypad.toFloat();
// Serial.println("KEYPAD JANCOKKKKKKKK= ");
// Serial.println(valueKeypad);
}
}
} else {
// Serial.println("404");
}
}
void tampilMenu() {
display.clearDisplay();
if (halaman == 1) {
stopstatus = false;
display.setTextSize(1.5);
display.setTextColor(WHITE);
display.getTextBounds("Smart Syringe Pump", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = (SCREEN_HEIGHT - h) / 10;
display.setCursor(panjang, lebar);
display.print("Smart Syringe Pump");
if (menuItem == 1) {
display.setCursor(5, 20);
display.setTextColor(WHITE);
display.print("> Dosage Feature");
} else {
display.setCursor(5, 20);
display.setTextColor(WHITE);
display.print(" Dosage Feature");
}
if (menuItem == 2) {
display.setCursor(5, 35);
display.setTextColor(WHITE);
display.print("> Flowrate Feature");
} else {
display.setCursor(5, 35);
display.setTextColor(WHITE);
display.print(" Flowrate Feature");
}
if (menuItem == 3) {
display.setCursor(5, 50);
display.setTextColor(WHITE);
display.print("> Refill");
} else {
display.setCursor(5, 50);
display.setTextColor(WHITE);
display.print(" Refill");
}
} else if (halaman == 2) {
menuDosageFeature();
} else if (halaman == 4) {
menuFlowrateFeature();
} else if (halaman == 5 ) {
display.setTextColor(WHITE);
display.setTextSize(1.5);
display.getTextBounds("Waiting Resetting", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = (SCREEN_HEIGHT - h) / 2;
display.setCursor(panjang, lebar);
display.print("Waiting Resetting");
// display.display();
refillSyringe();
}
else {
display.setCursor(5, (SCREEN_HEIGHT) / 2);
display.print("Amount: ");
display.print(tampungAmount);
display.print(satuanCairan);
}
display.display();
}
void menuDosageFeature() {
// untuk button up
if (UP && halaman == 2) {
UP = false;
menuItemDosage --;
if (menuItemDosage < 1)menuItemDosage = 2;
}
//untuk button down
if (DOWN && halaman == 2) {
DOWN = false;
menuItemDosage ++;
if (menuItemDosage > 2) menuItemDosage = 1;
}
// untuk button ok
if (OK) {
OK = false;
// patokDosageFeature++;
if (halaman == 2 && menuItemDosage == 1) {
// Serial.println("OK DITEKAN DOSAGE");
patokDosageFeature = 1;
// INPUT KEYPAD ANGKA
// Serial.println("TAMPUNG LAMA = ");
// Serial.println(tampung);
tampung ++;
if (tampung % 2 == 0) {
patokDosageFeature = 0;
}
// Serial.println("TAMPUNG SEKARANG = ");
// Serial.println(tampung);
delay(1000);
} else if (halaman == 2 && menuItemDosage == 2) {
// Serial.println("OK DITEKAN FlOWRATE");
patokDosageFeature = 2;
//INPUT KEYPAD ANGKA
// Serial.println("TAMPUNG LAMA = ");
// Serial.println(tampung);
tampung ++;
if (tampung % 2 == 0) {
patokDosageFeature = 0;
}
// Serial.println("TAMPUNG SEKARANG = ");
// Serial.println(tampung);
}
}
// Serial.println(menuItemDosage);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.getTextBounds("Dosage Feature", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = (SCREEN_HEIGHT - h) / 10;
display.setCursor(panjang, lebar);
display.print("Dosage Feature");
if (menuItemDosage == 1) {
if (patokDosageFeature == 1 ) {
display.setCursor(1, 25);
display.setTextColor(WHITE);
display.print(" Dosage:");
display.setCursor(55, 25);
display.setTextColor(WHITE);
display.print(uhuy);
display.print(satuanCairan);
// tampung +=1;
} else {
display.setCursor(1, 25);
display.setTextColor(WHITE);
display.print("> Dosage:");
display.setCursor(55, 25);
display.setTextColor(WHITE);
display.print(uhuy);
display.print(satuanCairan);
}
} else {
display.setCursor(1, 25);
display.setTextColor(WHITE);
display.print(" Dosage:");
display.setCursor(55, 25);
display.setTextColor(WHITE);
display.print(uhuy);
display.print(satuanCairan);
}
if (menuItemDosage == 2) {
if (patokDosageFeature == 2) {
display.setCursor(1, 40);
display.setTextColor(WHITE);
display.print(" Flowrate:");
display.setCursor(70, 40);
display.setTextColor(WHITE);
display.print(ihiy);
display.print(satuanFlowrate);
} else {
display.setCursor(1, 40);
display.setTextColor(WHITE);
display.print("> Flowrate:");
display.setCursor(70, 40);
display.setTextColor(WHITE);
display.print(ihiy);
display.print(satuanFlowrate);
}
} else {
display.setCursor(1, 40);
display.setTextColor(WHITE);
display.print(" Flowrate:");
display.setCursor(70, 40);
display.setTextColor(WHITE);
display.print(ihiy);
display.print(satuanFlowrate);
}
startDosage();
}
void startDosage() {
if (flowrate != 0 && dosage > 0 && dosage < 50 ) {
// Serial.println("Syringe Pump Siap Digunakan");
startDitekan();
// stopDitekan();
if (startstatus) {
// Serial.println("START DITEKAN PINDAH HALAMAN");
tampilanStart();
if (!startstatus && stopstatus == 0) {
splashScreenStop();
}
}
} else {
// Serial.println("Number < 0");
}
}
void startDitekan() {
if (statusBtnStart != statusAkhirBtnStart) {
if (statusBtnStart == 0) {
startstatus = true;
}
}
statusAkhirBtnStart = statusBtnStart;
}
// void stopDitekan() {
// if (statusBtnStop != statusAkhirBtnStop) {
// if (statusBtnStop == 0) {
// stopstatus = true;
// }
// }
// statusAkhirBtnStop = statusBtnStop;
// }
void tampilanStart() {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.getTextBounds("Running Feature", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = 2;
display.setCursor(panjang, lebar);
display.print("Running Feature");
display.setCursor(1, 18);
display.print("Dosis: ");
display.print(dosage);
display.print(satuanCairan);
display.setCursor(1, 30);
display.print("Flowrate: ");
display.print(flowrate);
display.print(satuanFlowrate);
display.setCursor(1, 40);
display.print("Inject: ");
display.setCursor(1, 50);
display.print("Amount:");
display.setCursor (50, 40);
display.print(inject);
display.print(satuanCairan);
display.setCursor (50, 50);
display.print(tampungAmount);
display.print(satuanCairan);
display.display();
int stepDosage = dosage * konstanta;
float patokFlowrate = flowrate ;
float delayt = (3600 / patokFlowrate)*dosage;
float delayMotor = delayt / stepDosage;
float konversiDelay = delayMotor * 1000;
stopstatus = digitalRead(stop);
if (startstatus) {
digitalWrite(dirPin, HIGH);
for (; p <= stepDosage; p++) {
stopstatus = digitalRead(stop);
Serial.println("STOP STATUS: ");
Serial.println(stopstatus);
Serial.println("NILAI STEP : ");
Serial.println(p);
Serial.println("NILAI DOSAGE: ");
Serial.println(stepDosage);
digitalWrite(stepPin, HIGH);
delay(konversiDelay / 2);
digitalWrite(stepPin, LOW);
delay(konversiDelay / 2);
if (p % 24 == 0 && p != 0) {
Serial.println("Kelipatan 24");
inject += 0.1;
tampungAmount -= 0.1;
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.getTextBounds("Running Feature", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = 2;
display.setCursor(panjang, lebar);
display.print("Running Feature");
display.setCursor(1, 18);
display.print("Dosis: ");
display.print(dosage);
display.print(satuanCairan);
display.setCursor(1, 30);
display.print("Flowrate: ");
display.print(flowrate);
display.print(satuanFlowrate);
display.setCursor(1, 40);
display.print("Inject: ");
display.setCursor(1, 50);
display.print("Amount: ");
display.setCursor (50, 40);
display.print(inject);
display.print(satuanCairan);
display.setCursor (50, 50);
display.print(tampungAmount);
display.print(satuanCairan);
display.display();
} else {
Serial.println("Sabarr");
}
if (stopstatus == 0) {
// patokDosageFeature = 0;
// // splashScreenStop();
Serial.println("DITEKANNNNN");
startstatus = false;
p = 0;
break;
}
}
Serial.println("UDAH SELESAI MASUK SINI");
startstatus = false;
p = 0;
}
}
void splashScreenStop() {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1.5);
display.getTextBounds("Emergency Stop", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = (SCREEN_HEIGHT - h) / 2;
display.setCursor(panjang, lebar);
display.print("Emergency Stop");
display.display();
delay(5000);
}
void menuFlowrateFeature() {
Serial.println(menuItemDosage);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1.5);
display.getTextBounds("Flowrate Feature", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = (SCREEN_HEIGHT - h) / 10;
display.setCursor(panjang, lebar);
display.print("Flowrate Feature");
display.getTextBounds("Flowrate Feature", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = (SCREEN_HEIGHT - h) / 10;
display.setCursor(panjang, lebar);
display.print("Flowrate Feature");
display.setTextSize(1.5);
display.setCursor(40, 20);
display.print("Flowrate:");
display.setCursor(40, 35);
display.print(valueKeypad);
display.print(satuanFlowrate);
startFlowrate();
}
void menustartFlowrate() {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.getTextBounds("Running Flowrate", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = 2;
display.setCursor(panjang, lebar);
display.print("Running Flowrate");
display.setCursor(1, 18);
display.print("Flowrate: ");
display.print(valueflowrateFeature);
display.setCursor(1, 30);
display.print("Inject: ");
display.setCursor(1, 40);
display.print("Amount: ");
display.setCursor(50, 40);
display.print(tampungAmount);
display.print(satuanCairan);
display.setCursor(50, 30);
display.print(inject);
display.print(satuanCairan);
display.display();
float patokFlowrate = valueflowrateFeature / konstanta;
float delayMotor = 3600 / patokFlowrate;
float konversiDelay = delayMotor * 1000;
// Clockwise
stopstatus = digitalRead(stop);
if (startstatus) {
digitalWrite(dirPin, HIGH);
for (; p <= 12000; p++) {
stopstatus = digitalRead(stop);
Serial.println("STOP STATUS: ");
Serial.println(stopstatus);
Serial.println("NILAI STEP : ");
Serial.println(p);
digitalWrite(stepPin, HIGH);
delay(konversiDelay / 2);
digitalWrite(stepPin, LOW);
delay(konversiDelay / 2);
if (p % 24 == 0 && p != 0) {
Serial.println("Kelipatan 24");
inject += 0.1;
tampungAmount -= 0.1;
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.getTextBounds("Running Flowrate", 0, 0, &x, &y, &w, &h);
panjang = (SCREEN_WIDTH - w) / 2; // Untu
lebar = 2;
display.setCursor(panjang, lebar);
display.print("Running Flowrate");
display.setCursor(1, 18);
display.print("Flowrate: ");
display.print(valueflowrateFeature);
display.setCursor(1, 30);
display.print("Inject: ");
display.setCursor(50, 30);
display.print(inject);
display.print(satuanCairan);
display.setCursor(1, 40);
display.print("Amount: ");
display.setCursor(50, 40);
display.print(tampungAmount);
display.print(satuanCairan);
display.display();
} else {
Serial.println("Sabarr");
}
if (stopstatus == 0) {
// patokDosageFeature = 0;
// // splashScreenStop();
Serial.println("DITEKANNNNN");
startstatus = false;
p = 0;
break;
}
}
startstatus = false;
}
}
void startFlowrate() {
if (valueflowrateFeature != 0) {
// Serial.println("Syringe Pump Flowrate Siap Digunakan");
startDitekan();
// stopDitekan();
if (startstatus) {
// Serial.println("START DITEKAN PINDAH HALAMAN");
if (valueflowrateFeature <= 50) {
menustartFlowrate();
if (!startstatus && stopstatus == 0) {
splashScreenStop();
}
}
// if (stopstatus) {
// // Serial.println("STOP SEDANG DITEKAN SELURUH PROGRESS DIHENTIKAN");
// startstatus = false;
// splashScreenStop();
// halaman = 1;
// }
} else {
// Serial.println("START TIDAK DITEKAN");
}
} else {
// Serial.println("Number < 0");
}
}
void refillSyringe() {
float calculateStep = 50 - tampungAmount ;
float stepAmount = calculateStep / konstanta;
float refill = stepAmount * konstanta;
Serial.println("HASILL NILAI REFILL = ");
Serial.println(refill);
Serial.println("HASILL NILAI CALCULATE STEP = ");
Serial.println(calculateStep);
Serial.println("HASILL NILAI STEP AMOUNT = ");
Serial.println(stepAmount);
Serial.println("HASILL NILAI P = ");
Serial.println(p);
// Counter Clockwise
digitalWrite(dirPin, LOW);
for (; p <= stepAmount; p++) {
Serial.println("CEK INJECT: ");
Serial.println(inject);
Serial.println("CEK AMOUNT: ");
Serial.println(tampungAmount);
display.display();
Serial.println("NILAI STEP : ");
Serial.println(p);
digitalWrite(stepPin, HIGH);
delay(500);
digitalWrite(stepPin, LOW);
delay(500);
if (p % 24 == 0 && p != 0) {
Serial.println("Kelipatan 24");
tampungAmount += 0.1;
} else {
Serial.println("Sabarr Lagi Refill");
}
// if (stopstatus == 0) {
// // patokDosageFeature = 0;
// // // splashScreenStop();
// Serial.println("DITEKANNNNN");
// startstatus = false;
// p = 0;
// break;
// }
}
p = 0;
halaman = 1;
}