#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 pIn analogRead(A0)
#define input_ref analogRead(A2)
#define right digitalRead(4)
#define enter digitalRead(3)
#define left digitalRead(2)
const int pinOut = 9;
int pCounter = 0;
char tArr1[2] = {};
char tArr2[2] = {};
char tArr3[2] = {};
float pwr = 0.0;
float pVal = 0.0;
float pVal2 = 0.0;
byte pOut;
byte b_pOut[2];
int refl = 0.0;
float reflVal = 0.0;
int reflect = 0;
int subCounter = 0;
int menuCounter = 0;
int buttonState = 0;
int enterState = 0;
byte w_delta[8] =
{
B11000,
B10100,
B10010,
B10001,
B10001,
B10010,
B10100,
B11000
};
byte b_delta[8] =
{
B11000,
B11100,
B11110,
B11111,
B11111,
B11110,
B11100,
B11000
};
void setup() {
lcd.init();
lcd.backlight();
lcd.createChar(0, w_delta);
lcd.createChar(1, b_delta);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(A0, INPUT);
pinMode(A1, OUTPUT);
pinMode(A2, INPUT);
}
//Proses
void bgProses(){
pwr = (float)pCounter;
pVal2 = float(pwr/10) * 1023.0;
pVal = floor(pVal2/15);
//pVal = floor(255);
b_pOut[0] = int(pVal)/256;
b_pOut[1] = int(pVal)%256;
pOut = b_pOut[0]*256 + b_pOut[1];
analogWrite(pinOut, (byte)pOut);
//refl = pIn;
refl = (input_ref * 1000.0) / 1024.0;
}
// 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 power(){
lcd.setCursor(2,1);
lcd.print("Power : ");
lcd.setCursor(10,1);
lcd.print(pCounter);
}
void reflected(){
lcd.setCursor(2,2);
lcd.print("Refl : ");
lcd.setCursor(10,2);
lcd.print(refl, 1);
}
void rfin(){
lcd.setCursor(2,3);
lcd.print("RF IN : ");
}
void menu1(){
lcd.clear();
bgProses();
title1();
power();
reflected();
rfin();
delay(150);
}
//MENU 2
void title2(){
lcd.setCursor(5,0);
lcd.print("Temp Status");
lcd.setCursor(19,1);
lcd.print("C");
lcd.setCursor(19,2);
lcd.print("C");
lcd.setCursor(19,3);
lcd.print("C");
}
void temp1(){
lcd.setCursor(2,1);
lcd.print("Temp 1 : ");
}
void temp2(){
lcd.setCursor(2,2);
lcd.print("Temp 2 : ");
}
void temp3(){
lcd.setCursor(2,3);
lcd.print("Temp 3 : ");
}
void menu2(){
lcd.clear();
title2();
temp1();
temp2();
temp3();
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(){
lcd.setCursor(2,1);
lcd.print("Arus 1 : ");
}
void arus2(){
lcd.setCursor(2,2);
lcd.print("Arus 2 : ");
}
void arus3(){
lcd.setCursor(2,3);
lcd.print("Arus 3 : ");
}
void menu3(){
lcd.clear();
title3();
arus1();
arus2();
arus3();
delay(150);
}
void (*menuSelection[])(void) = {
menu1,
menu2,
menu3
};
void menu(){
menuSelection[menuCounter]();
if(right == LOW && buttonState == 0){
menuCounter++;
if(menuCounter > 2){
menuCounter = 0;
}
}
if(left == LOW && buttonState == 0){
menuCounter--;
if(menuCounter < 0){
menuCounter = 2;
}
}
//MENU 1 SETUP
if(enter == LOW && menuCounter == 0){
bgProses();
enterState = 1;
buttonState = 1;
while(enterState == 1){
menu1();
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 == 0 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
menu1();
lcd.setCursor(0,1);
lcd.write(1);
delay(150);
if(right == LOW && buttonState == 2){
pCounter += 5;
if(pCounter >= 100){
pCounter = 100;
}
}
if(left == LOW && buttonState == 2){
pCounter -= 5;
if(pCounter <= 0){
pCounter = 0;
}
}
if(enter == LOW && enterState == 2){
enterState = 0;
buttonState = 0;
subCounter = 0;
return menuSelection[0];
}
}
}
}
}
//MENU 2 SETUP
if( enter == LOW && menuCounter == 1){
enterState = 1;
buttonState = 1;
while(enterState == 1){
menu2();
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 == 0 && enter == LOW){
enterState = 2;
buttonState = 2;
while(enterState == 2){
lcd.clear();
lcd.setCursor(2,1);
lcd.print("SET LIMIT TEMP 1");
lcd.setCursor(10,2);
lcd.print("C");
delay(150);
if(right == LOW && buttonState == 2){
tArr1[0]++;
}
}
}
}
}
}
void loop(){
menu();
}