#include <LiquidCrystal_I2C.h> // if you don´t have I2C version of the display, use LiquidCrystal.h library instead
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
//LiquidCrystal_I2C lcd(0x3f,16,2); // set the LCD address to 0x3f for a 16 chars and 2 line display
// if you don´t know the I2C address of the display, use I2C scanner first (https://playground.arduino.cc/Main/I2cScanner/)
// define custom characters/arrays - every character is 5x8 "pixels"
byte gauge_empty[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; // empty middle piece
byte gauge_fill_1[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111}; // filled gauge - 1 column
byte gauge_fill_2[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11111}; // filled gauge - 2 columns
byte gauge_fill_3[8] = {B11111, B11100, B11100, B11100, B11100, B11100, B11100, B11111}; // filled gauge - 3 columns
byte gauge_fill_4[8] = {B11111, B11110, B11110, B11110, B11110, B11110, B11110, B11111}; // filled gauge - 4 columns
byte gauge_fill_5[8] = {B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111}; // filled gauge - 5 columns
byte gauge_left[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111}; // left part of gauge - empty
byte gauge_right[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111}; // right part of gauge - empty
byte gauge_mask_left[8] = {B01111, B11111, B11111, B11111, B11111, B11111, B11111, B01111}; // mask for rounded corners for leftmost character
byte gauge_mask_right[8] = {B11110, B11111, B11111, B11111, B11111, B11111, B11111, B11110}; // mask for rounded corners for rightmost character
byte warning_icon[8] = {B00100, B00100, B01110, B01010, B11011, B11111, B11011, B11111}; // warning icon - just because we still have one custom character left
byte gauge_left_dynamic[8]; // left part of gauge dynamic - will be set in the loop function
byte gauge_right_dynamic[8]; // right part of gauge dynamic - will be set in the loop function
int cpu_gauge = 0; // value for the CPU gauge
char buffer[10]; // helper buffer to store C-style strings (generated with sprintf function)
int move_offset = 0; // used to shift bits for the custom characters
const int gauge_size_chars = 16; // width of the gauge in number of characters
char gauge_string[gauge_size_chars+1]; // string that will include all the gauge character to be printed
int out1 (13);//pln
int out2 (12);//loss
int out3 (11);//genset
int starter (3);//starter mesin genset
int off (4);//off genset
int button (2);//saklar pilihan switch
int count1;
int status1;
void setup(){
lcd.begin(16, 2);
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("SYSTEM ATS ");
lcd.setCursor(0, 1);
lcd.print("BY LUTFI BUHORI");
pinMode(button, INPUT);
pinMode(out1, OUTPUT);
pinMode(out2, OUTPUT);
pinMode(out3, OUTPUT);
pinMode(starter, OUTPUT);
pinMode(off, OUTPUT);
}
void loop()
{
status1 = digitalRead(button);
if (status1 == HIGH){
count1++;
delay(1000);
if(count1 == 1){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SUMBER LISTRIK ");
lcd.setCursor(0, 1);
lcd.print("DARI===> PLN");
digitalWrite(off, HIGH);
delay(2000);
digitalWrite(off, LOW);
digitalWrite(out3, LOW);
delay(3000);
digitalWrite(out1, HIGH);
}
if(count1 == 2){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SUMBER LISTRIK ");
lcd.setCursor(0, 1);
lcd.print("DARI==> LOSS-KWH");
digitalWrite(out1, LOW);
delay(3000);
digitalWrite(out2, HIGH);
}
if(count1 == 3){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("NYALAHKAN MESIN ");
lcd.setCursor(0, 1);
lcd.print("STARTER GENSET");
digitalWrite(starter, HIGH);
delay(1500);
digitalWrite(starter, LOW);
digitalWrite(out2, LOW);
delay(3000);
digitalWrite(out3, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SUMBER LISTRIK ");
lcd.setCursor(0, 1);
lcd.print("DARI==> GENSET");
count1=0;
}
}
}