#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Pin untuk masing-masing sensor tegangan (sesuaikan dengan koneksi Anda)
const int sensorPin1 = A0;
const int sensorPin2 = A1;
const int sensorPin3 = A2;
// Pin untuk masing-masing tombol (sesuaikan dengan koneksi Anda)
const int tombol1 = 2;
const int tombol2 = 3;
const int tombol3 = 4;
const int tombol4 = 5;
// Inisialisasi LCD
LiquidCrystal_I2C lcd(0x27, 20, 4); // Sesuaikan alamat I2C jika berbeda
// Variabel untuk menyimpan status tombol
int state1 = 0;
int state2 = 0;
int state3 = 0;
int state4 = 0;
void setup() {
// Set pin tombol sebagai input
pinMode(tombol1, INPUT_PULLUP);
pinMode(tombol2, INPUT_PULLUP);
pinMode(tombol3, INPUT_PULLUP);
pinMode(tombol4, INPUT_PULLUP);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
// Inisialisasi LCD
lcd.init();
lcd.backlight();
lcd.setCursor(3, 1);
lcd.print("Loading");
delay(1000);
lcd.setCursor(3, 1);
lcd.print("Loading.");
delay(1000);
lcd.setCursor(3, 1);
lcd.print("Loading..");
delay(1000);
lcd.setCursor(3, 1);
lcd.print("Loading...");
delay(500);
lcd.setCursor(3, 1);
lcd.print("Loading....");
delay(500);
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("CONTROLLER CHECKER");
delay(1000);
lcd.setCursor(0, 3);
lcd.print("Back|Vbat|VPs|CCheck");
delay(1000);
}
void loop() {
// Baca status tombol
state1 = digitalRead(tombol1);
state2 = digitalRead(tombol2);
state3 = digitalRead(tombol3);
state4 = digitalRead(tombol4);
// Jika tombol 1 ditekan
if (state1 == LOW) {
int nilaiSensor1 = analogRead(sensorPin1);
float tegangan1 = nilaiSensor1 * (5.0 / 1023.0);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" Teg Baterai: ");
lcd.setCursor(5, 2);
lcd.print(tegangan1);
lcd.print("V");
delay(500); // Tunda sebentar agar tampilan stabil
}
// Jika tombol 2 ditekan
else if (state2 == LOW) {
// ... (sama seperti tombol 1, ganti sensorPin1 dengan sensorPin2)
int nilaiSensor2 = analogRead(sensorPin2);
float tegangan2 = nilaiSensor2 * (5.0 / 1023.0);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" Teg P.Supply: ");
lcd.setCursor(5, 2);
lcd.print(tegangan2);
lcd.print("V");
delay(500); // Tunda sebentar agar tampilan stabil
}
// Jika tombol 3 ditekan
else if (state3 == LOW) {
// ... (sama seperti tombol 1, ganti sensorPin1 dengan sensorPin3)
int nilaiSensor1 = analogRead(sensorPin1);
int nilaiSensor2 = analogRead(sensorPin2);
int nilaiSensor3 = analogRead(sensorPin3);
float tegangan1 = nilaiSensor1 * (5.0 / 1023.0);
float tegangan2 = nilaiSensor2 * (5.0 / 1023.0);
float tegangan3 = nilaiSensor3 * (5.0 / 1023.0);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("BACA DATA 0 %");
delay(1000);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 2 %");
delay(800);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 5 %");
delay(800);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 10 %");
delay(800);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 15 %");
delay(600);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 20 %");
delay(400);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 25 %");
delay(400);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 30 %");
delay(400);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 40 %");
delay(400);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 50 %");
delay(400);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 60 %");
delay(300);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 70 %");
delay(200);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 80 %");
delay(200);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 90 %");
delay(200);
lcd.setCursor(0, 0);
lcd.print("BACA DATA 100 %");
delay(500);
//lcd.clear();
//lcd.setCursor(0, 0);
//lcd.print("Sensor 3 Check:");
if (tegangan1 >= 3 && tegangan2 >= 3 && tegangan3 >= 3){
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("GOOD");
lcd.setCursor(0, 1);
lcd.print(" CAN Power Supply");
lcd.setCursor(0, 2);
lcd.print(" 1 2 1 2 3");
lcd.setCursor(0, 3);
lcd.print("5V 5V 5V 5V 5V");
digitalWrite(13, HIGH);
delay(2000);
digitalWrite(13, LOW);
delay(1000);
} else {
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("FAULT");
lcd.setCursor(0, 1);
lcd.print(" CAN Power Supply");
lcd.setCursor(0, 2);
lcd.print(" 1 2 1 2 3");
lcd.setCursor(0, 3);
lcd.print("5V 0V 0V 5V 5V");
digitalWrite(12, HIGH);
delay(5000);
digitalWrite(12, LOW);
delay(1000);
}
delay(2000);
}
// Jika tombol 4 ditekan
else if (state4 == LOW) {
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("CONTROLLER CHECKER");
delay(100);
lcd.setCursor(0, 3);
lcd.print("Back|Vbat|VPs|CCheck");
delay(100);
}
}