#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
LiquidCrystal_I2C lcd(0x27,20,4); //LiquidCrystal_I2C lcd(0x20,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display or 20 chars and 4 line display
#define right digitalRead(4)
#define enter digitalRead(3)
#define left digitalRead(2)
#define pwmPin A0
#define reflin analogRead(A1)
#define arusIn analogRead(A2)
#define vcc analogRead(A3)
#define tempIn analogRead(A6)
#define led1 5
#define led2 6
#define led3 7
#define led4 8
#define led5 11
//menu variable
int pCounter = 0;
int mode = 0;
int subCounter = 0;
int menuCounter = 0;
int buttonState = 0;
int enterState = 0;
String lock[] = {"Lock","Unlock"};
int menuState = 0;
int chCount = 0;
//limit
bool overVal = true;
//temp variable
int tVal1, tVal2, tVal3;
int t1 = 70, t2 = 70, t3 = 70;
float tV1, tV2, tV3;
int tCount1, tCount11, tCount2, tCount22, tCount3, tCount33;
int tempLim1, tempLim2, tempLim3;
//arus variable
int aVal1, aVal2, aVal3;
int a1 = 10, a2 = 10, a3 = 10;
float aV1, aV2, aV3;
int aCount1, aCount11, aCount2, aCount22, aCount3, aCount33;
int currLim1, currLim2, currLim3;
//volt variable
int vVal1, vVal2, vVal3;
int v1 = 70, v2 = 70, v3 = 70;
float vV1, vV2, vV3;
int vCount1, vCount11, vCount2, vCount22, vCount3, vCount33;
int voltLim1, voltLim2, voltLim3;
//power variable
const int pinOut = 9;
byte PWM;
float pwrIn;
int pwmMon;
int pwr = 0;
float pwrVal= 0.0;
float pVal = 0.0;
byte pOut;
byte b_pOut[2];
float refl = 0.0;
int reflect = 0;
float limVal = 10.0;
//frequency variable
int freq1, freq2, freq3, freq4;
float freq;
float f_freq;
byte *ptr_val0;
float value0;
String frekuensi;
String batasFrekuensi[14] =
{ "87.7",
"87.9",
"88.1",
"88.3",
"88.5",
"88.7",
"88.9",
"106.7",
"106.9",
"107.1",
"107.3",
"107.5",
"107.7",
"107.9"};
//LOCK MODE VARIABLE
String pwd;
String comp;
int passwd[4];
int pwdArc = 0;
int pMenuArc = 0;
String astrk = "****";
int pwdState = 0;
int i = 0, j = 0, k = 0, l = 0;
int a = 0, b = 0, c = 0, d = 0;
//symblo variable
byte w_delta[8] =
{
B11000,
B10100,
B10010,
B10001,
B10001,
B10010,
B10100,
B11000
};
byte b_delta[8] =
{
B11000,
B11100,
B11110,
B11111,
B11111,
B11110,
B11100,
B11000
};
byte circle[8] =
{
B01110,
B10001,
B10001,
B01110,
B00000,
B00000,
B00000,
B00000
};
byte val_ptr[8] =
{
B00100,
B01010,
B10001,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte lock_1[8] =
{
B00000,
B00000,
B00111,
B01111,
B11111,
B11100,
B11100,
B11100
};
byte lock_2[8] =
{
B00000,
B00000,
B11100,
B11110,
B11111,
B00111,
B00111,
B00111
};
byte lock_3[8] =
{
B11111,
B11111,
B11111,
B11100,
B11100,
B11111,
B11111,
B11111
};
byte lock_4[8] =
{
B11111,
B11111,
B11111,
B00111,
B00111,
B11111,
B11111,
B11111
};
void setup() {
lcd.init();
lcd.backlight();
lcd.createChar(0, w_delta);
lcd.createChar(1, b_delta);
lcd.createChar(2, circle);
lcd.createChar(3, val_ptr);
lcd.createChar(4, lock_1);
lcd.createChar(5, lock_2);
lcd.createChar(6, lock_3);
lcd.createChar(7, lock_4);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(11, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A6, INPUT);
pinMode(A1, OUTPUT);
}
//Proses
void bgProses(){
pVal = (float)pCounter;
pVal = float(pVal/1000) * 1023.0;
pOut = floor(pVal/4);
analogWrite(pinOut, (byte)pOut);
//PWM Monitor
PWM = getPwm(pwmPin);
pwrIn = float(PWM)/1023.0;
pwrIn = ceil(pwrIn * 1000.0);
pwrIn = pwrIn * 10;
pwmMon = (int)PWM;
//reflected
refl = (50.0 * reflin) / 1023.0;
limVal = (1.0 / refl) * pCounter;
//temp
tV1 = (100.0 * tempIn) / 1023.0;
tV2 = (100.0 * tempIn) / 1023.0;
tV3 = (100.0 * tempIn) / 1023.0;
tempLim1 = (tCount1 * 10) + tCount11;
tempLim2 = (tCount2 * 10) + tCount22;
tempLim3 = (tCount3 * 10) + tCount33;
//arus
aV1 = (100.0 * arusIn) / 1023.0;
aV2 = (100.0 * arusIn) / 1023.0;
aV3 = (100.0 * arusIn) / 1023.0;
currLim1 = (aCount1 * 10) + aCount11;
currLim2 = (aCount2 * 10) + aCount22;
currLim3 = (aCount3 * 10) + aCount33;
//vcc
vV1 = (100.0 * vcc) / 1023.0;
vV2 = (100.0 * vcc) / 1023.0;
vV3 = (100.0 * vcc) / 1023.0;
//frequency
freq = (float)(freq1*100 + freq2*10 + freq3 + freq4*0.1);
f_freq = freq;
}
byte getPwm(byte pin){
unsigned long highTime = pulseIn(pin, HIGH, 50000);
unsigned long lowTime = pulseIn(pin, LOW, 50000);
if(highTime == 0 || lowTime == 0){
return analogRead(pin) ? 100 : 0;
}
return (100*highTime)/(highTime + lowTime);
}
// MENU 1
void title1(){
lcd.setCursor(3,0);
lcd.print("RF Power Status");
lcd.setCursor(19,1);
lcd.print("W");
lcd.setCursor(19,2);
lcd.print("W");
lcd.setCursor(19,3);
lcd.print("W");
}
void setUp(){
lcd.setCursor(2,1);
lcd.print("Set Power : ");
lcd.setCursor(13,1);
lcd.print(pCounter);
}
void power(){
lcd.setCursor(2,2);
lcd.print("Power : ");
lcd.setCursor(13,2);
lcd.print(pwr);
}
void reflected(){
lcd.setCursor(2,3);
lcd.print("Refl : ");
lcd.setCursor(13,3);
lcd.print(refl, 1);
}
void pwmMonitor(){
lcd.clear();
lcd.setCursor(2,0);
lcd.print("PWM Monitor: ");
lcd.setCursor(15,0);
lcd.print(pwmMon);
lcd.setCursor(2,2);
lcd.print("Enter Setup");
lcd.setCursor(2,3);
lcd.print("Exit");
delay(150);
}
void menu1(){
lcd.clear();
bgProses();
setUp();
title1();
power();
reflected();
delay(150);
}
//MENU 2
void title2(){
lcd.setCursor(5,0);
lcd.print("Temp Status");
lcd.setCursor(18,1);
lcd.write(2);
lcd.setCursor(19,1);
lcd.print("C");
lcd.setCursor(18,2);
lcd.write(2);
lcd.setCursor(19,2);
lcd.print("C");
lcd.setCursor(18,3);
lcd.write(2);
lcd.setCursor(19,3);
lcd.print("C");
}
void temp1(){
int tArray1[] = {t1, tV1};
lcd.setCursor(2,1);
lcd.print("Temp 1 : ");
lcd.setCursor(11,1);
lcd.print(tArray1[tVal1]);
}
void temp2(){
int tArray2[] = {t2, tV2};
lcd.setCursor(2,2);
lcd.print("Temp 2 : ");
lcd.setCursor(11,2);
lcd.print(tArray2[tVal2]);
}
void temp3(){
int tArray3[] = {t3, tV3};
lcd.setCursor(2,3);
lcd.print("Temp 3 : ");
lcd.setCursor(11,3);
lcd.print(tArray3[tVal3]);
}
void menu2(){
lcd.clear();
bgProses();
title2();
temp1();
temp2();
temp3();
delay(150);
if(tV1 > 0){
tVal1 = 1;
}
if(tV2 > 0){
tVal2 = 1;
}
if(tV3 > 0){
tVal3 = 1;
}
}
//FUNCTION TO LIMIT TEMP
void tLim1(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT TEMP 1 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(tCount1);
lcd.setCursor(9,2);
lcd.print(tCount11);
lcd.setCursor(10,2);
lcd.write(2);
lcd.setCursor(11,2);
lcd.print("C");
delay(150);
}
void tLim2(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT TEMP 2 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(tCount2);
lcd.setCursor(9,2);
lcd.print(tCount22);
lcd.setCursor(10,2);
lcd.write(2);
lcd.setCursor(11,2);
lcd.print("C");
delay(150);
}
void tLim3(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT TEMP 3 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(tCount3);
lcd.setCursor(9,2);
lcd.print(tCount33);
lcd.setCursor(10,2);
lcd.write(2);
lcd.setCursor(11,2);
lcd.print("C");
delay(150);
}
//MENU 3
void title3(){
lcd.setCursor(5,0);
lcd.print("Arus Status");
lcd.setCursor(19,1);
lcd.print("A");
lcd.setCursor(19,2);
lcd.print("A");
lcd.setCursor(19,3);
lcd.print("A");
}
void arus1(){
int aArray1[] = {a1, aV1};
lcd.setCursor(2,1);
lcd.print("Arus 1 : ");
lcd.setCursor(11,1);
lcd.print(aArray1[aVal1]);
}
void arus2(){
int aArray2[] = {a2, aV2};
lcd.setCursor(2,2);
lcd.print("Arus 2 : ");
lcd.setCursor(11,2);
lcd.print(aArray2[aVal2]);
}
void arus3(){
int aArray3[] = {a3, aV3};
lcd.setCursor(2,3);
lcd.print("Arus 3 : ");
lcd.setCursor(11,3);
lcd.print(aArray3[aVal3]);
}
void menu3(){
lcd.clear();
bgProses();
title3();
arus1();
arus2();
arus3();
delay(150);
if(aV1 > 0){
aVal1 = 1;
}
if(aV2 > 0){
aVal2 = 1;
}
if(aV3 > 0){
aVal3 = 1;
}
}
//FUNCTION TO LIMIT ARUS
void aLim1(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT ARUS 1 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(aCount1);
lcd.setCursor(9,2);
lcd.print(aCount11);
lcd.setCursor(11,2);
lcd.print("A");
delay(150);
}
void aLim2(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT ARUS 2 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(aCount2);
lcd.setCursor(9,2);
lcd.print(aCount22);
lcd.setCursor(11,2);
lcd.print("A");
delay(150);
}
void aLim3(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT ARUS 3 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(aCount3);
lcd.setCursor(9,2);
lcd.print(aCount33);
lcd.setCursor(11,2);
lcd.print("A");
delay(150);
}
//MENU 4
void title4(){
lcd.setCursor(9,0);
lcd.print("VCC");
lcd.setCursor(19,1);
lcd.print("V");
lcd.setCursor(19,2);
lcd.print("V");
lcd.setCursor(19,3);
lcd.print("V");
}
void volt1(){
int vArray1[] = {v1, vV1};
lcd.setCursor(2,1);
lcd.print("Volt 1 : ");
lcd.setCursor(11,1);
lcd.print(vArray1[vVal1]);
}
void volt2(){
int vArray2[] = {v2, vV2};
lcd.setCursor(2,2);
lcd.print("Volt 2 : ");
lcd.setCursor(11,2);
lcd.print(vArray2[vVal2]);
}
void volt3(){
int vArray3[] = {v3, vV3};
lcd.setCursor(2,3);
lcd.print("Volt 3 : ");
lcd.setCursor(11,3);
lcd.print(vArray3[vVal3]);
}
void menu4(){
lcd.clear();
bgProses();
title4();
volt1();
volt2();
volt3();
delay(150);
if(vV1 > 0){
vVal1 = 1;
}
if(vV2 > 0){
vVal2 = 1;
}
if(vV3 > 0){
vVal3 = 1;
}
}
//FUNCTION TO LIMIT VOLT
void vLim1(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT VOLT 1 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(vCount1);
lcd.setCursor(9,2);
lcd.print(vCount11);
lcd.setCursor(11,2);
lcd.print("V");
delay(150);
}
void vLim2(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT VOLT 2 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(vCount2);
lcd.setCursor(9,2);
lcd.print(vCount22);
lcd.setCursor(11,2);
lcd.print("V");
delay(150);
}
void vLim3(){
lcd.clear();
lcd.setCursor(1,1);
lcd.print("SET LIMIT VOLT 3 : ");
lcd.setCursor(6,2);
lcd.write(1);
lcd.setCursor(8,2);
lcd.print(vCount3);
lcd.setCursor(9,2);
lcd.print(vCount33);
lcd.setCursor(11,2);
lcd.print("V");
delay(150);
}
//MENU 5
void menu5(){
lcd.clear();
lcd.setCursor(4,0);
lcd.print("Frequency : ");
lcd.setCursor(5,2);
ptr_val0 = (byte *)&f_freq;
EEPROM.write(1, *ptr_val0++);
EEPROM.write(2, *ptr_val0++);
EEPROM.write(3, *ptr_val0++);
EEPROM.write(4, *ptr_val0);
ptr_val0 = (byte *)&value0;
*ptr_val0++ = EEPROM.read(1);
*ptr_val0++ = EEPROM.read(2);
*ptr_val0++ = EEPROM.read(3);
*ptr_val0 = EEPROM.read(4);
lcd.print(value0);
frekuensi = String(value0, 1);
lcd.setCursor(12,2);
lcd.print("MHZ");
delay(150);
if(frekuensi == batasFrekuensi[0]){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
else if(frekuensi == batasFrekuensi[1]){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
else if(frekuensi == batasFrekuensi[2]){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
else if(frekuensi == batasFrekuensi[3]){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
else if(frekuensi == batasFrekuensi[4]){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
}
else if(frekuensi == batasFrekuensi[5]){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
}
else if(frekuensi == batasFrekuensi[6]){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
}
else if(frekuensi == batasFrekuensi[7]){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
}
else if(frekuensi == batasFrekuensi[8]){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
}
else if(frekuensi == batasFrekuensi[9]){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
}
else if(frekuensi == batasFrekuensi[10]){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
}
else if(frekuensi == batasFrekuensi[11]){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
}
else if(frekuensi == batasFrekuensi[12]){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
}
else if(frekuensi == batasFrekuensi[13]){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
}
else{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
}
//MENU 5 SETUP
void freqSetup(){
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Set Frequency : ");
lcd.setCursor(4,2);
lcd.write(1);
lcd.setCursor(6,2);
lcd.print(freq1);
lcd.setCursor(7,2);
lcd.print(freq2);
lcd.setCursor(8,2);
lcd.print(freq3);
lcd.setCursor(9,2);
lcd.print(".");
lcd.setCursor(10,2);
lcd.print(freq4);
lcd.setCursor(13,2);
lcd.print("MHZ");
delay(150);
}
//Menu 6 or Lock Mode
void lockMode(){
String passArr[] = {"Change Password", "Password"};
bgProses();
lcd.clear();
lcd.setCursor(6,0);
lcd.print("Settings");
lcd.setCursor(2,1);
lcd.print("Save");
lcd.setCursor(2,2);
lcd.print(lock[mode]);
lcd.setCursor(2,3);
lcd.print(passArr[pMenuArc]);
delay(150);
}
void tit1(){
lcd.clear();
lcd.setCursor(4,0);
lcd.print("Set Password");
delay(150);
}
void paswd1(){
lcd.setCursor(8,2);
lcd.print(i);
}
void paswd2(){
lcd.setCursor(9,2);
lcd.print(j);
}
void paswd3(){
lcd.setCursor(10,2);
lcd.print(k);
}
void paswd4(){
lcd.setCursor(11,2);
lcd.print(l);
}
void tit2(){
String pwdArr[] = {pwd, astrk};
lcd.clear();
lcd.setCursor(2,1);
lcd.print("Curr. Pwd :");
lcd.setCursor(15,1);
lcd.print(pwdArr[pwdArc]);
lcd.setCursor(2,2);
lcd.print("Change Password");
lcd.setCursor(2,3);
lcd.print("Exit");
delay(150);
}
void tit3(){
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Enter Password");
delay(150);
}
void paswd5(){
lcd.setCursor(8,2);
lcd.print(a);
}
void paswd6(){
lcd.setCursor(9,2);
lcd.print(b);
}
void paswd7(){
lcd.setCursor(10,2);
lcd.print(c);
}
void paswd8(){
lcd.setCursor(11,2);
lcd.print(d);
}
void (*menuSelection[])(void) = {
menu1,
menu2,
menu3,
menu4,
menu5,
lockMode
};
void menu(){
menuSelection[menuCounter]();
if(right == LOW && buttonState == 0){
menuCounter++;
if(menuCounter > 5){
menuCounter = 0;
}
}
if(left == LOW && buttonState == 0){
menuCounter--;
if(menuCounter < 0){
menuCounter = 5;
}
}
if(mode == 0){
//MENU 1 SETUP
if(enter == LOW && menuCounter == 0){
enterState = 1;
buttonState = 1;
while(enterState == 1){
lcd.setCursor(0,1);
lcd.write(1);
delay(150);
menuSelection[0]();
if(right == LOW && buttonState == 1){
pCounter += 20;
pwr += 20;
if(pCounter >= 1000){
pCounter = 1000;
}
}
if(left == LOW && buttonState == 1){
pCounter -= 20;
pwr +=20;
if(pCounter <= 0){
pCounter = 0;
}
}
if(enter == LOW && enterState == 1){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[0];
}
}
}
//MENU 2 SETUP
if( enter == LOW && menuCounter == 1){
enterState = 1;
buttonState = 1;
while(enterState == 1){
menuSelection[1]();
switch(subCounter){
case 0:
lcd.setCursor(0,1);
lcd.write(0);
delay(150);
break;
case 1:
lcd.setCursor(0,2);
lcd.write(0);
delay(150);
break;
case 2:
lcd.setCursor(0,3);
lcd.write(0);
delay(150);
break;
}
if(right == LOW && buttonState == 1){
subCounter++;
if(subCounter > 2){
subCounter = 0;
}
}
if(left == LOW && buttonState == 1){
subCounter--;
if(subCounter < 0){
subCounter = 2;
}
}
//TEMP 1
if(subCounter == 0 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
tLim1();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
tCount1++;
if(tCount1 > 9){
tCount1 = 0;
}
}
if(left == LOW && buttonState == 2){
tCount1--;
if(tCount1 < 0){
tCount1 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
tLim1();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
tCount11++;
if(tCount11 > 9){
tCount11 = 0;
}
}
if(left == LOW && buttonState == 3){
tCount11--;
if(tCount11 < 0){
tCount11 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[1];
}
}
}
}
}
//TEMP 2
if(subCounter == 1 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
tLim2();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
tCount2++;
if(tCount2 > 9){
tCount2 = 0;
}
}
if(left == LOW && buttonState == 2){
tCount2--;
if(tCount2 < 0){
tCount2 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
tLim2();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
tCount22++;
if(tCount22 > 9){
tCount22 = 0;
}
}
if(left == LOW && buttonState == 3){
tCount22--;
if(tCount22 < 0){
tCount22 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[1];
}
}
}
}
}
//TEMP 3
if(subCounter == 2 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
tLim3();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
tCount3++;
if(tCount3 > 9){
tCount3 = 0;
}
}
if(left == LOW && buttonState == 2){
tCount3--;
if(tCount3 < 0){
tCount3 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
tLim3();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
tCount33++;
if(tCount33 > 9){
tCount33 = 0;
}
}
if(left == LOW && buttonState == 3){
tCount33--;
if(tCount33 < 0){
tCount33 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
tVal3 = 1;
return menuSelection[1];
}
}
}
}
}
}
}
//MENU 3 SETUP
if( enter == LOW && menuCounter == 2){
enterState = 1;
buttonState = 1;
while(enterState == 1){
menuSelection[2]();
switch(subCounter){
case 0:
lcd.setCursor(0,1);
lcd.write(0);
delay(150);
break;
case 1:
lcd.setCursor(0,2);
lcd.write(0);
delay(150);
break;
case 2:
lcd.setCursor(0,3);
lcd.write(0);
delay(150);
break;
}
if(right == LOW && buttonState == 1){
subCounter++;
if(subCounter > 2){
subCounter = 0;
}
}
if(left == LOW && buttonState == 1){
subCounter--;
if(subCounter < 0){
subCounter = 2;
}
}
//ARUS 1
if(subCounter == 0 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
aLim1();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
aCount1++;
if(aCount1 > 9){
aCount1 = 0;
}
}
if(left == LOW && buttonState == 2){
aCount1--;
if(aCount1 < 0){
aCount1 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
aLim1();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
aCount11++;
if(aCount11 > 9){
aCount11 = 0;
}
}
if(left == LOW && buttonState == 3){
aCount11--;
if(aCount11 < 0){
aCount11 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[2];
}
}
}
}
}
//ARUS 2
if(subCounter == 1 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
aLim2();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
aCount2++;
if(aCount2 > 9){
aCount2 = 0;
}
}
if(left == LOW && buttonState == 2){
aCount2--;
if(aCount2 < 0){
aCount2 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
aLim2();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
aCount22++;
if(aCount22 > 9){
aCount22 = 0;
}
}
if(left == LOW && buttonState == 3){
aCount22--;
if(aCount22 < 0){
aCount22 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[2];
}
}
}
}
}
//ARUS 3
if(subCounter == 2 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
aLim3();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
aCount3++;
if(aCount3 > 9){
aCount3 = 0;
}
}
if(left == LOW && buttonState == 2){
aCount3--;
if(aCount3 < 0){
aCount3 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
aLim3();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
aCount33++;
if(aCount33 > 9){
aCount33 = 0;
}
}
if(left == LOW && buttonState == 3){
aCount33--;
if(aCount33 < 0){
aCount33 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[2];
}
}
}
}
}
}
}
//MENU 4
if( enter == LOW && menuCounter == 3){
enterState = 1;
buttonState = 1;
while(enterState == 1){
menuSelection[3]();
switch(subCounter){
case 0:
lcd.setCursor(0,1);
lcd.write(0);
delay(150);
break;
case 1:
lcd.setCursor(0,2);
lcd.write(0);
delay(150);
break;
case 2:
lcd.setCursor(0,3);
lcd.write(0);
delay(150);
break;
}
if(right == LOW && buttonState == 1){
subCounter++;
if(subCounter > 2){
subCounter = 0;
}
}
if(left == LOW && buttonState == 1){
subCounter--;
if(subCounter < 0){
subCounter = 2;
}
}
//vOLT 1
if(subCounter == 0 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
vLim1();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
vCount1++;
if(vCount1 > 9){
vCount1 = 0;
}
}
if(left == LOW && buttonState == 2){
vCount1--;
if(vCount1 < 0){
vCount1 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
vLim1();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
vCount11++;
if(vCount11 > 9){
vCount11 = 0;
}
}
if(left == LOW && buttonState == 3){
vCount11--;
if(vCount11 < 0){
vCount11 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[3];
}
}
}
}
}
//VOLT 2
if(subCounter == 1 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
vLim2();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
vCount2++;
if(vCount2 > 9){
vCount2 = 0;
}
}
if(left == LOW && buttonState == 2){
vCount2--;
if(vCount2 < 0){
vCount2 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
vLim2();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
vCount22++;
if(vCount22 > 9){
vCount22 = 0;
}
}
if(left == LOW && buttonState == 3){
vCount22--;
if(vCount22 < 0){
vCount22 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[3];
}
}
}
}
}
//VOLT 3
if(subCounter == 2 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
vLim3();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
vCount3++;
if(vCount3 > 9){
vCount3 = 0;
}
}
if(left == LOW && buttonState == 2){
vCount3--;
if(vCount3 < 0){
vCount3 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
vLim3();
lcd.setCursor(9,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
vCount33++;
if(vCount33 > 9){
vCount33 = 0;
}
}
if(left == LOW && buttonState == 3){
vCount33--;
if(vCount33 < 0){
vCount33 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[3];
}
}
}
}
}
}
}
//MENU 5
if(enter == LOW && menuCounter == 4){
enterState = 1;
buttonState = 1;
while(enterState == 1){
bgProses();
freqSetup();
lcd.setCursor(6,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 1){
freq1++;
if(freq1 >= 1){
freq1 = 1;
}
}
if(left == LOW && buttonState == 1){
freq1--;
if(freq1 <= 0){
freq1 = 0;
}
}
if(enter == LOW && enterState == 1){
enterState = 2;
buttonState = 2;
while(enterState == 2){
bgProses();
freqSetup();
lcd.setCursor(7,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 2){
freq2++;
if(freq2 > 9){
freq2 = 0;
}
}
if(left == LOW && buttonState == 2){
freq2--;
if(freq2 < 0){
freq2 = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
bgProses();
freqSetup();
lcd.setCursor(8,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 3){
freq3++;
if(freq3 > 9){
freq3 = 0;
}
}
if(left == LOW && buttonState == 3){
freq3--;
if(freq3 < 0){
freq3 = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 4;
buttonState = 4;
while(enterState == 4){
bgProses();
freqSetup();
lcd.setCursor(10,3);
lcd.write(3);
delay(150);
if(right == LOW && buttonState == 4){
freq4++;
if(freq4 > 9){
freq4 = 0;
}
}
if(left == LOW && buttonState == 4){
freq4--;
if(freq4 < 0){
freq4 = 9;
}
}
if(enter == LOW && enterState == 4){
enterState = 0;
buttonState = 0;
return menuSelection[4];
}
}
}
}
}
}
}
}
}
}
//MENU 6
if(enter == LOW && menuCounter == 5){
enterState = 1;
buttonState = 1;
while(enterState == 1){
lockMode();
switch(subCounter){
case 0:
lcd.setCursor(0,1);
lcd.write(0);
delay(150);
break;
case 1:
lcd.setCursor(0,2);
lcd.write(0);
delay(150);
break;
case 2:
lcd.setCursor(0,3);
lcd.write(0);
delay(150);
break;
}
if(right == LOW && buttonState == 1){
subCounter++;
if(subCounter > 2){
subCounter = 0;
}
}
if(left == LOW && buttonState == 1){
subCounter--;
if(subCounter < 0){
subCounter = 2;
}
}
if(subCounter == 1 && enter == LOW && mode == 0){
if(pwdState == 1){
enterState = 2;
buttonState = 2;
while(enterState == 2){
lockMode();
mode = 1;
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[5];
}
}
else{
lcd.clear();
lcd.setCursor(4,1);
lcd.print("Please setup");
lcd.setCursor(3,2);
lcd.print("your password !");
delay(1000);
}
}
if(subCounter == 1 && enter == LOW && mode == 1){
if(pwdState == 1){
enterState = 2;
buttonState = 2;
while(enterState == 2){
tit3();
paswd5();
delay(300);
if(right == LOW && buttonState == 2){
a++;
if(a > 9){
a = 0;
}
}
if(left == LOW && buttonState == 2){
a--;
if(a < 0){
a = 9;
}
}
if(enter == LOW && enterState == 2){
enterState = 3;
buttonState = 3;
while(enterState == 3){
tit3();
paswd5();
paswd6();
delay(300);
if(right == LOW && buttonState == 3){
b++;
if(b > 9){
b = 0;
}
}
if(left == LOW && buttonState == 3){
b--;
if(b < 0){
b = 9;
}
}
if(enter == LOW && enterState == 3){
enterState = 4;
buttonState = 4;
while(enterState == 4){
tit3();
paswd5();
paswd6();
paswd7();
delay(300);
if(right == LOW && buttonState == 4){
c++;
if(c > 9){
c = 0;
}
}
if(left == LOW && buttonState == 4){
c--;
if(c < 0){
c = 9;
}
}
if(enter == LOW && enterState == 4){
enterState = 5;
buttonState = 5;
while(enterState == 5){
tit3();
paswd5();
paswd6();
paswd7();
paswd8();
delay(300);
if(right == LOW && buttonState == 5){
d++;
if(d > 9){
d = 0;
}
}
if(left == LOW && buttonState == 5){
d--;
if(d < 0){
d = 9;
}
}
if(enter == LOW && enterState == 5){
comp = String(a) + String(b) + String(c) + String(d);
if(comp == pwd){
mode = 0;
}
if(comp != pwd){
mode = 1;
a = 0; b = 0; c = 0; d = 0;
lcd.clear();
lcd.setCursor(3,1);
lcd.print("Wrong Password !");
delay(1000);
}
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[5];
}
}
}
}
}
}
}
}
}
}
if(subCounter == 2 && enter == LOW ){
enterState = 1;
buttonState = 1;
while(enterState == 1){
while(pwdState == 0){
tit1();
paswd1();
delay(300);
if(right == LOW && buttonState == 1){
i++;
if(i > 9){
i = 0;
}
}
if(left == LOW && buttonState == 1){
i--;
if(i < 0){
i = 9;
}
}
if(enter == LOW && enterState == 1){
passwd[0] = i;
enterState = 2;
buttonState = 2;
while(enterState == 2){
tit1();
paswd1();
paswd2();
delay(300);
if(right == LOW && buttonState == 2){
j++;
if(j > 9){
j = 0;
}
}
if(left == LOW && buttonState == 2){
j--;
if(j < 0){
j = 9;
}
}
if(enter == LOW && enterState == 2){
passwd[1] = j;
enterState = 3;
buttonState = 3;
while(enterState == 3){
tit1();
paswd1();
paswd2();
paswd3();
delay(300);
if(right == LOW && buttonState == 3){
k++;
if(k > 9){
k = 0;
}
}
if(left == LOW && buttonState == 3){
k--;
if(k < 0){
k = 9;
}
}
if(enter == LOW && enterState == 3){
passwd[2] = k;
enterState = 4;
buttonState = 4;
while(enterState == 4){
tit1();
paswd1();
paswd2();
paswd3();
paswd4();
delay(300);
if(right == LOW && buttonState == 4){
l++;
if(l > 9){
l = 0;
}
}
if(left == LOW && buttonState == 4){
l--;
if(l < 0){
l = 9;
}
}
if(enter == LOW && enterState == 4){
passwd[3] = l;
enterState = 5;
buttonState = 5;
while (enterState == 5){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Save Password ?");
lcd.setCursor(2,3);
lcd.print("Yes");
lcd.setCursor(16,3);
lcd.print("No");
delay(150);
switch(chCount){
case 0:
lcd.setCursor(0,3);
lcd.write(0);
delay(150);
break;
case 1:
lcd.setCursor(14,3);
lcd.write(0);
delay(150);
break;
}
if(right == LOW && buttonState == 5){
chCount++;
if(chCount > 1){
chCount = 0;
}
}
if(left == LOW && buttonState == 5){
chCount--;
if(chCount < 0){
chCount = 1;
}
}
if(chCount == 0 && enter == LOW){
enterState = 0;
buttonState = 0;
subCounter = 0;
chCount = 0;
pwd = String(i) + String(j) + String(k) + String(l);
pwdArc = 1;
pMenuArc = 1;
pwdState = 1;
return menuSelection[5];
}
if(chCount == 1 && enter == LOW){
i = 0; j = 0; k = 0; l = 0;
enterState = 0;
buttonState = 0;
subCounter = 0;
chCount = 0;
pwdState = 0;
pwdArc = 0;
pMenuArc = 0;
return menuSelection[5];
}
}
}
}
}
}
}
}
}
}
if(mode == 0){
while(pwdState == 1){
tit2();
switch(chCount){
case 0:
lcd.setCursor(0,1);
lcd.write(0);
delay(150);
break;
case 1:
lcd.setCursor(0,2);
lcd.write(0);
delay(150);
break;
case 2:
lcd.setCursor(0,3);
lcd.write(0);
delay(150);
break;
}
if(right == LOW && buttonState == 1){
chCount++;
if(chCount > 2){
chCount = 0;
}
}
if(left == LOW && buttonState == 1){
chCount--;
if(chCount < 0){
chCount = 2;
}
}
if(chCount == 0 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
tit2();
lcd.setCursor(0,1);
lcd.write(1);
delay(150);
pwdArc = 0;
if(enter == LOW && buttonState == 2){
enterState = 1;
buttonState = 1;
pwdArc = 1;
}
}
}
if(chCount == 1 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState = 2){
tit2();
enterState = 0;
buttonState = 0;
subCounter = 0;
chCount = 0;
i = 0; j = 0; k = 0; l = 0;
pwdState = 0;
pMenuArc = 0;
return menuSelection[5];
}
}
if(chCount == 2 && enter == LOW){
if(pwdState == 0){
pwdState = 0;
}
if(pwdState == 1){
pwdState = 1;
}
chCount = 0;
subCounter = 0;
buttonState = 0;
enterState = 0;
return menuSelection[5];
}
}
}
else{
if(enter == LOW){
subCounter = 0;
lcd.clear();
lcd.setCursor(5,1);
lcd.write(4);
lcd.setCursor(6,1);
lcd.write(5);
lcd.setCursor(8,1);
lcd.print("Setup is");
lcd.setCursor(5,2);
lcd.write(6);
lcd.setCursor(6,2);
lcd.write(7);
lcd.setCursor(8,2);
lcd.print("Locked !");
delay(1000);
return menu();
}
}
}
}
}
}
if(mode == 1){
bgProses();
if(enter == LOW){
lcd.clear();
lcd.setCursor(5,1);
lcd.write(4);
lcd.setCursor(6,1);
lcd.write(5);
lcd.setCursor(8,1);
lcd.print("Setup is");
lcd.setCursor(5,2);
lcd.write(6);
lcd.setCursor(6,2);
lcd.write(7);
lcd.setCursor(8,2);
lcd.print("Locked !");
delay(1000);
return menu();
}
}
}
void loop(){
menu();
//lim
if(mode == 0 || mode == 1){
if(refl > limVal || tV1 > tempLim1 || tV2 > tempLim2 || tV3 > tempLim3 || aV1 > currLim1 || aV2 > currLim2 || aV3 > currLim3 && overVal){
digitalWrite(11, HIGH);
pwr -= 15;
if(pwr < 0){
pwr = 0;
}
}
else{
if(pwr < pCounter){
pwr += 20;
if(pwr >= pCounter){
pwr = pCounter;
}
}
overVal = false;
digitalWrite(11, LOW);
}
delay(150);
}
}