hey all,
i have made my project thanks to all the peoples that share their projects and knowledge.
that's why didn't remove the names of whom i borrewd the info.
that said,
in my code, when i stay in an other menu then menu A (the one with timer). and i go to menu A after a time (more than 60seconds) then the timer when ik enter menu A starts to show the time counting up untill it's "live" can i adjust code that when i enter menu A it just displays the current situation,
and not displaying all the lost time untill live?
/*+++++++++++++++++++++++++++++++++++++++++++++++++++
Author : Fahmi Ghani
Date : 5 July 2015
Project : LCD Menu Function
Component : LCD Keypad shield
Description : Simple Menu function on LCD
Button Function:
Up/Down - change Menu Page
Select - enter page
Left - Exit
Video Link: http://youtu.be/cMqif5ICS5M
+++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int keypad_pin = A0;
int keypad_value = 0;
int keypad_value_old = 0;
char btn_push;
byte mainMenuPage = 1;
byte mainMenuPageOld = 1;
byte mainMenuTotal = 6;
const int ThermistorPin1 = 1;
const int ThermistorPin2 = 2;
const int ThermistorPin3 = 3;
const int start_pin = 12;
unsigned long PreviousMillis1;
unsigned long PreviousMillis2;
bool Changed = true; // Update display
int Vo1;
int Vo2;
int Vo3;
int Vo4;
float R1 = 10000;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
int h = 0;
int m = 0;
int s = 0;
double q1 = 0.45; //grootte van de verstuiver
double q2 = 0;
int p1 = 6.89; //standaard druk verstuiver 100 psi is 6.89 bar
double p2 = 12; //druk gemeten aan pomp
int v2 = 3000; //volume van de tank
double v1 = 0; //volume verbruikt
int v3 = 0; //overschot in tank
double d = 0; //bereking dagen millis
void setup()
{
lcd.begin(16, 2); //Initialize a 2x16 type LCD
pinMode(start_pin, INPUT_PULLUP);
MainMenuDisplay();
delay(50);
}
void loop()
{
btn_push = ReadKeypad();
MainMenuBtn();
if (btn_push == 'S') //enter selected menu
{
WaitBtnRelease();
switch (mainMenuPage)
{
case 1:
MenuA();
break;
case 2:
MenuB();
break;
case 3:
MenuC();
break;
case 4:
MenuD();
break;
case 5:
MenuE();
break;
case 6:
MenuF();
break;
// case 7:
//MenuG();
// break;
}
MainMenuDisplay();
WaitBtnRelease();
}
delay(10);
}//--------------- End of loop() loop ---------------------
void MenuA()
{
lcd.clear();
lcd.setCursor(0, 0);
//lcd.print("Inside Menu A");
while (ReadKeypad() != 'L')
{
//Insert Task for Menu A here
unsigned long currentMillis1 = millis();
if (currentMillis1 - PreviousMillis1 >= 1000)
{
PreviousMillis1 += 1000;
//// input van de timer
if (digitalRead(start_pin) == LOW)
{
// Reduce flicker by only updating the LCD when
// the display values have changed
s++;
if (s == 60)
{
s = 0;
m++;
if (m == 60)
{
m = 0;
h++;
} // end hrs check
} // end minutes check
} // end seconds check
lcd.setCursor(0, 0); //setting start point on lcd
lcd.print("TIME:"); //writting TIME
lcd.print(h); //writing hours
lcd.print(":");
if (m < 10) lcd.print("0");
lcd.print(m); //writing minutes
lcd.print(":");
if (s < 10) lcd.print("0");
lcd.print(s); //writing seconds
//uur omzetten naar verbruikte liters
q2 = q1 * sqrt(p2 / 6.895) * 3.785;
v1 = q2 * h + q2 * m / 60;
v3 = v2 - v1;
lcd.setCursor(0, 1);
lcd.print(v1);
lcd.print("L") ;
lcd.setCursor(11, 1);
lcd.print(v3);
lcd.print("L");
}
}
}
void MenuB()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Inside Menu B");
while (ReadKeypad() != 'L')
{
//Insert Task for Menu B here
Vo1 = analogRead(ThermistorPin1);
R2 = R1 * (1023.0 / (float)Vo1 - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
T = T - 273.15;
lcd.setCursor(0, 0);
lcd.print("Tgas=");
lcd.print(T);
lcd.print(" C");
//sensor 2 uitlaattemp gas schouw
Vo2 = analogRead(ThermistorPin2);
R2 = R1 * (1023.0 / (float)Vo2 - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
T = T - 273.15;
lcd.setCursor(0, 1);
lcd.print("Tschw=");
lcd.print(T);
lcd.print(" C");
delay(500);// delay en clear altijd opt laatste van de loop anders flikkerend scherm in miliseconde
lcd.clear();
}
}
void MenuC()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("verstuiver");
//lcd.setCursor(0, 1);
//lcd.print(q1);
//lcd.print("GPH");
while (ReadKeypad() != 'L')
{
btn_push = ReadKeypad();
//definieren van verstuiver in gph bvb 0.45 gph
//Insert Task for Menu C here
if (btn_push == 'U')
{
WaitBtnRelease();
q1 = q1 + 0.05;
}
if (btn_push == 'D')
{
WaitBtnRelease();
q1 = q1 - 0.05;
}
lcd.setCursor(0, 1);
lcd.print(q1);
lcd.print(" GPH");
}
}
void MenuD()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pompdruk");
while (ReadKeypad() != 'L')
{
//Insert Task for Menu D here
btn_push = ReadKeypad();
//definieren van pompdruk
//Insert Task for Menu C here
if (btn_push == 'U')
{
WaitBtnRelease();
p2 = p2 + 0.5;
}
if (btn_push == 'D')
{
WaitBtnRelease();
p2 = p2 - 0.5;
}
lcd.setCursor(0, 1);
if (p2 < 10) lcd.print("0");
lcd.print(p2);
lcd.print(" BAR");
}
}
void MenuE()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Volume tank");
while (ReadKeypad() != 'L')
{
//Insert Task for Menu E here
btn_push = ReadKeypad();
//definieren van pompdruk
//Insert Task for Menu C here
if (btn_push == 'U')
{
WaitBtnRelease();
v2 = v2 + 50;
}
if (btn_push == 'D')
{
WaitBtnRelease();
v2 = v2 - 50;
}
lcd.setCursor(0, 1);
lcd.print(v2);
lcd.print(" Liter");
}
}
void MenuF()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Dagen meting");
while (ReadKeypad() != 'L')
{
//Insert Task for Menu F here
unsigned long currentMillis2 = millis();
if (currentMillis2 - PreviousMillis2 >= 1000) //864000)
{
PreviousMillis2 += 1000;//864000;
d = d + 0.01;
}
lcd.setCursor(0, 1);
lcd.print(d);
lcd.print(" dagen");
}
}
/*void MenuG()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Inside Menu G");
while (ReadKeypad() != 'L')
{
//Insert Task for Menu G here
}
}*/
void MainMenuDisplay()
{
lcd.clear();
lcd.setCursor(0, 0);
switch (mainMenuPage)
{
case 1:
lcd.print("1.Verbruik");
break;
case 2:
lcd.print("2.Temperaturen");
break;
case 3:
lcd.print("3.Debiet verstvr");
break;
case 4:
lcd.print("4.Druk ingesteld");
break;
case 5:
lcd.print("5.Volume tank");
break;
case 6:
lcd.print("6.Dagen meting");
break;
//case 7:
// lcd.print("7. Menu G");
// break;
}
}
void MainMenuBtn()
{
WaitBtnRelease();
if (btn_push == 'U')
{
mainMenuPage++;
if (mainMenuPage > mainMenuTotal)
mainMenuPage = 1;
}
else if (btn_push == 'D')
{
mainMenuPage--;
if (mainMenuPage == 0)
mainMenuPage = mainMenuTotal;
}
if (mainMenuPage != mainMenuPageOld) //only update display when page change
{
MainMenuDisplay();
mainMenuPageOld = mainMenuPage;
}
}
char ReadKeypad()
{
/* Keypad button analog Value
no button pressed 1023
select 741
left 503
down 326
up 142
right 0
*/
keypad_value = analogRead(keypad_pin);
if (keypad_value < 100)
return 'R';
else if (keypad_value < 200)
return 'U';
else if (keypad_value < 400)
return 'D';
else if (keypad_value < 600)
return 'L';
else if (keypad_value < 800)
return 'S';
else
return 'N';
}
void WaitBtnRelease()
{
while ( analogRead(keypad_pin) < 800) {}
}