how to refresh screen with arduino

hello guys i’m making a small menu for a user interface with an oled but i’m stuck with problem for like three days and i can’t find where the problems is

i want te show live measurment but the numbers don’t change only if i go out of the page and get back to it

can you tell me what to change in my code so it can be working

#include <SPI.h>
#include<Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

#define startbutton 2
int currentscreen  ;
unsigned long time;
 
 float u;
 float z;
 float i=0;
 float f; // reading battery value
  volatile boolean current =false;
  volatile boolean voltage =false;
long int seconds=0;
int minutes=0;
int hours=0;
long int c;
  int a=1;
  float v;
  unsigned long previousmillis =0;
unsigned long interval = 1000;
volatile boolean startt ;
volatile boolean sb ;
volatile boolean khra=true; ;
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);


void isr0() {
  sb= digitalRead(startbutton);
  startt = true;
}
 
void setup() {
   
  Serial.begin(115200);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.clearDisplay();
  delay(2000);
   attachInterrupt (digitalPinToInterrupt(2), isr0, CHANGE);
  display.setTextSize(1);
  display.setTextColor(WHITE);
screen1();
 display.clearDisplay();
 screen2();
}



void loop() {
if (voltage){
   f =analogRead(A0);//reading battery value
  c= (hours*1000*a)+(minutes*1000*a)/60;
  v=(f/1023)*5 ; // battery voltage
}
    
 if(current){
   u =analogRead(A1);//reading current value
    z =(u/1023)*5; //voltage across resistor 
    i = z/2.2 ; // current passing through resistor
    Serial.println(i);
  }

  
  if (startt ){
  delay(200);
  
  switch (currentscreen){
    
    case 2:
     current= true;
   screen3();
  
   break;
   
  case 3: 
  current =false;
    screen4();
     
  break;

   case 4: 
  
  screen5();
  
  break;
   case 5: 
  
  
    screen2();
     
  break;
  }

 startt=false; 
}

}

void setClock()

{


 if(millis() > previousmillis + interval){
        previousmillis = millis();
        seconds++;}

if (seconds>59)
{
seconds=0;      
minutes++;     
}
if (minutes>59)
{hours++;
minutes=0;
}
if(hours>23)
{
hours=0;
}
}
void screen1(){
  display.clearDisplay();
 
  display.setCursor(15,5);
 display.println("battery discharger");
 display.setCursor(15,20);
 display.println("by SKANDER BELHAJ");
display.display();
 delay (4000);
 currentscreen=1;
 
 
}

void screen2() {
  display.clearDisplay();
  display.setCursor(15,5);
  display.println("PLACE BATTERY ");
  display.setCursor(15,20);
  display.println("AND PRESS START ");
  display.display();
  currentscreen=2;
}

void screen3 (){
  display.clearDisplay();
  display.setCursor(35,15);
  display.print("SELECT AMPS");
   display.setCursor(50,25);
  display.print(i);
  
  display.display();
  currentscreen=3;
}

void screen4(){
  display.clearDisplay();
  display.setCursor(30,5);
  display.print("LOW VOLTAGE");
  display.setCursor(60,15);
  display.print("/");
  display.setCursor(30,25);
  display.print("NO BATTERY");
  display.display();
  currentscreen=4;
}
void screen5(){
  display.clearDisplay();
   display.setCursor(0,0);
  display.println("V = ");  
   display.setCursor(20,0);
  display.println(u,1);  
  display.setCursor(80,0);
  display.println("A =");
   display.setCursor(100,0);
  display.println(f,1);  
  display.setCursor(0,25);
  display.println("T =");
   display.setCursor(80,25);
  display.println("C =");
  display.setCursor(100,25);
  display.print(c);
display.display();

 setClock();  

           
display.setCursor(20,25);      
if(hours<10)       
{   
display.print("0");     
display.print(hours);
}                     
else
{
display.setCursor(20,25);
display.print(hours);
}
 display.setCursor(30,25);
display.print(":");
if(minutes<10)
{
display.setCursor(30,25);
display.print(":");
display.print("0");
display.print(minutes);
display.print(":");
}
else
{   
display.print(minutes);
display.print(":");
}
if(seconds<10)
{
display.print("0");
display.print(seconds);
}
else
{display.print(seconds);}
    display.display();
currentscreen=5;
}

Hi,
Have you looked at the Adafruit examples?

Tom… :slight_smile:

The only time loop() displays anything is when the variable 'startt' is true. The only time that variable is true is when it gets set to true in the ISR triggered by a button press (and release) but then gets set to false so no further action is taken.