how to refresh data values whithout having to go back to first menu page

i have made a voltmeter and an uptimer inside an lcd menu but it doesn’t refresh only if i go out and then get back can some one please help me here ???


#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define btn 9
#define btn2 10
#define btn3 8
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
float voltage0, voltage1, voltage2 ,resistor , volts0, volts1, volts2;
int dl=200;
long int seconds=0;
int minutes=0;
int hours=0;
char screen = 0;
char flechepos = 0;
char count=0;
volatile boolean enter = false;
volatile boolean select = false;
volatile boolean menu = false ;

unsigned long time;
byte fleche[8] = {
0b10000,
0b11000,
0b11100,
0b11110,
0b11110,
0b11100,
0b11000,
0b10000
};

byte mark[8]={
0b00110,
0b01001,
0b01001,
0b00010,
0b00100,
0b00100,
0b00000,
0b00100
};

byte doura[8]={
0b00111,
0b00101,
0b00111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
};

void setup() {
lcd.begin(16,2);
Serial.begin(9600);

for (int i=8 ; i<12; i++)
{
pinMode(i,INPUT_PULLUP);
}
/* lcd.setCursor(4,0);
lcd.print("BATTERY ");
lcd.setCursor(4,1);
lcd.print(“CHARGER”);
delay(5000);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("MADE BY ");
lcd.setCursor(1,1);
lcd.print(“SKANDER BELHAJ”);
delay(5000);
*/
lcd.clear();
lcd.createChar(0,fleche);
lcd.createChar(1,mark);
lcd.createChar(2,doura);
lcd.clear();
screen0();
lcd.setCursor(0,0);
lcd.write((uint8_t)0);

}

void loop(){

voltage0= analogRead(A0);
voltage1= analogRead(A1);
voltage2= analogRead(A2);
volts0 = (voltage0/1024)*5 ;
volts1 = (voltage1/1024)*5 ;
volts2 = (voltage2/1024)*5 ;

Serial.println(seconds);

if (digitalRead(btn) == HIGH) {
select = true;
count++;
}

if (digitalRead(btn2) == HIGH) {
enter = true;

}

if (digitalRead(btn3) == HIGH) {
menu = true;

}

if(select){
delay(200);
switch(screen){
case 0:
switch(flechepos){

case 0:
if((count%2)==1){
screen0();
lcd.setCursor(0, 1);
lcd.write((uint8_t)0);
flechepos = 1;

}
break;

case 1:
if ((count%2)==0){
screen0();
lcd.setCursor(0, 0);
lcd.write((uint8_t)0);
flechepos = 0;

}
break;
}
break;
}
select = false;

}

if(enter){

switch(screen){

case 0:
if (flechepos==0){

screen1();
screen=1;
delay(dl);
}
else if(flechepos==1){
screen4();
screen=4;
}
break;

case 1:
screen2();
lcd.setCursor(0,0);
lcd.write((uint8_t)0);
screen=2;
delay(dl);
break;

case 2:

screen3();
screen=3;
delay(dl);

break;

case 4:
screen5();
screen=5;
delay(dl);
break;

case 5:
screen6();
screen=6;
delay(dl);
break;

case 6:
screen=7;
screen7();
setClock();
lcd.setCursor(12,0);
if(hours<10)
{

lcd.print(hours);
lcd.print(":");
}
else
{
lcd.print(hours);
lcd.print(":");
}

if(minutes<10)
{
lcd.print(“0”);
lcd.print(minutes);
}
else
{
lcd.print(minutes);
}

delay(dl);

break;
}

enter =false;
}

if (menu){
screen0();

screen=0;
lcd.setCursor(0,0);
lcd.write((uint8_t)0);

switch(screen){
case 0:
switch(flechepos){

case 0:
if((count%2)==1){
screen0();

lcd.setCursor(0, 1);
lcd.write((uint8_t)0);
flechepos = 1;

}
break;

case 1:
if ((count%2)==0){
screen0();
lcd.setCursor(0, 0);
lcd.write((uint8_t)0);
flechepos = 0;

}
break;
}
break;
}
select = false;
flechepos=0;
count=0;
menu =false;

}

}

void screen0(){
lcd.clear();
lcd.setCursor(1,0);
lcd.print(“CHARGE BATT”);
lcd.setCursor(1,1);
lcd.print(“DISCHARGE BATT”);

}

void screen1(){
lcd.clear();
lcd.setCursor(5,0);
lcd.print(“PLEASE”);
lcd.setCursor(0,1);
lcd.print(“PLACE BATTERIES”);

}

void screen2(){
lcd.clear();
lcd.setCursor(1,0);
lcd.print(“START”);
lcd.write((uint8_t)1);
}

void screen3(){
lcd.clear();

lcd.setCursor(0,0);
lcd.print(“bat1”);
lcd.setCursor(0,1);
lcd.print(volts0,1);
lcd.print(“v”);

lcd.setCursor(6,0);
lcd.print(“bat2”);
lcd.setCursor(6,1);
lcd.print(volts1,1);
lcd.print(“v”);

lcd.setCursor(12,0);
lcd.print(“bat3”);
lcd.setCursor(12,1);
lcd.print(volts2,1);
lcd.print(“v”);

}

void screen4(){

lcd.clear();
lcd.setCursor(1,0);
lcd.print(“PLACE BATTERY”);
lcd.setCursor(3,1);
lcd.print(“IN ROW N”);
lcd.setCursor(11,1);
lcd.write((uint8_t)2);
lcd.setCursor(12,1);
lcd.print(“4”);
}
void screen5(){
lcd.clear();
lcd.setCursor(3,0);
lcd.print(“SELECT AMPS”);

}

void screen6(){
lcd.clear();
lcd.setCursor(1,0);
lcd.print(“START”);
lcd.setCursor(6,0);
lcd.write((uint8_t)1);
lcd.setCursor(0,0);
lcd.write((uint8_t)0);

}

void screen7(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“AMP:”);
lcd.setCursor(0,1);
lcd.print(“V:”);
lcd.setCursor(7,0);
lcd.print("TIME ");
lcd.setCursor(8,1);
lcd.print(“mah:”);
}
void setClock()
{

seconds++;
delay(1000);
if (seconds>59)
{
seconds=0;
minutes++;
}
if (minutes>59)
{hours++;
minutes=0;
}
if(hours>23)
{
hours=0;
}
}

sketch_aug08b.ino (5.48 KB)

Hello belhajskander,
Welcome to the forum.

Please read ‘how to use this forum, please read’, particularly item #7, then go back and modify your original post to include code tags around your code.

Also consider the other things asked for an whether you have asked a clear question and provided all the requested information.

Thank you.

...and STOP POSTING THE SAME QUESTION IN DIFFERENT PARTS OF THE FORUM

say something useful

Hard to be useful when you have provided almost nothing useful to describe your problem, but instead expecting us to scroll through screens worth of garbage.

What do you think is preventing the code from following the menu selection moves the user entered in a loop and displaying the current values?

My hint would be that the user “has” to press a button to back out then things update.

exactly thr problem so what should i change w remove ??

@belhajskander

Please modify your first post for the code section and use code tags ( </> ).
The forum chews up code when presented your way.
It also annoys people who have to scroll for miles.

May I also suggest you read the posts at the top of this forum section before adding any other posts as the advice in those sticky’s will help you get the best out of the forum.

Bob.