Hello All,
I am beginner in programming. I am using pH sensor with Arduino Uno. i have successfully run pH sensor and Menu program(using Switch case). But, i am having problem while i am merging both program into one file. I want to display pH value, date, time in a real time(Main screen info) and i set a condition when i press a button from keypad shield it should jump to menu program. But it is not working.
can somebody will help me in this regard??
Here is my program:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,04);
unsigned long int avgValue;
float b;
#define SensorPin A0
int buf[10],temp;
double phaddress1=0;
byte Oldkey = 6;
byte Buttonstatus = 0;
byte Menulevel = 0;
byte Row;
byte Column;
int offset;
void setup() {
lcd.init();
lcd.backlight();
Row=0;
Column=0;
}
void loop() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("pH:");
pH();
if (Buttonstatus==0){
Menu();
}
}
void pH(){
for(int i=0;i<15;i++)
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++)
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++)
avgValue+=buf[i];
float phValue=(float)avgValue5.0/1024/6;
lcd.setCursor(3,0);
lcd.print(phValue);
phValue=3.5phValue+offset;
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
}
void Menu(){
switch (Menulevel){
case 0:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Press Select Button");
lcd.setCursor(0,1);
lcd.print("to continue...");
Buttonstatus = get_key(Oldkey);
if (Buttonstatus == 0)
{
Menulevel = 1;
}
break;
case 1:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("1. Date and time ");
lcd.setCursor(0,1);
lcd.print("2. pH ");
lcd.setCursor(Column,Row);
lcd.print("");
Buttonstatus = get_key(Oldkey);
if (Buttonstatus == 2)
{
while (Row <1)
{
Row++;
lcd.setCursor(Column,Row);
lcd.print("");
break;
}
}
if (Buttonstatus == 3)
{
while (Row>0)
{
Row--;
lcd.setCursor(Column,Row);
lcd.print("*");
break;
}
}
if (Buttonstatus == 4)
{
Menulevel = 10 + Row;
Row = 0;
}
if (Buttonstatus == 1)
{
Menulevel = 0;
Row = 0;
}
break;
}
}