Skip to main content
added 1091 characters in body
Source Link

My Minute() function is as followscode:

void#include Minute<LiquidCrystal.h>
 

LiquidCrystal lcd(8, 9, 4, 5, 6, 7){;


int lcd_key     = 0;
int First_Digitadc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     144
#define btnDOWN   329
#define btnLEFT   504
#define btnSELECT 741
#define btnNONE   5
 

int read_LCD_buttons()
{
 adc_key_in = analogRead(0);    

 if (adc_key_in > 1000) return btnNONE; 
 if (adc_key_in < 50)   return btnRIGHT; 
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;  
 return btnNONE;
 

}
unsigned long minInterval = 60000UL; // Interval for minutes in milliseconds
unsigned long secInterval = 1000UL;  // Interval for seconds in milliseconds
unsigned long prevMinMillis = 0UL;   // Holds the timestamp of the last time Minute() was called
unsigned long prevSecMillis = 0UL;   // Holds the timestamp of the last time Second() was called

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

void loop()
{
  unsigned long currentMillis = millis();

  if (currentMillis - prevMinMillis > minInterval)
  {
    prevMinMillis = currentMillis;
    Minute();
  }

  if (currentMillis - prevSecMillis > secInterval)
  {
    prevSecMillis = currentMillis;
    Second();
  }

}

void Second(){
  int First_Digit = 0;
  int Second_Digit = 0;
  

  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);}
      }
    lcd.setCursor(30, 0);
    lcd.print(First_Digit);
    lcd.setCursor(41, 0);
    lcd.print(Second_Digit);
    delay(60000);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      lcd.print(First_Digit);
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      Second_Digit = Second_Digit - 10;
      }
    
  }
}

And my Second():

    void SecondMinute(){
      int First_Digit = 0;
      int Second_Digit = 0;
    
      for(Second_Digit; Second_Digit<10; Second_Digit++){
        if(Second_Digit==10){
          First_Digit = First_Digit + 1;
          }lcd.print(First_Digit);
        }
  
      
    lcd.setCursor(03, 0);
        lcd.print(First_Digit);
        lcd.setCursor(14, 0);
        lcd.print(Second_Digit);
        delay(1000);
        lcd.clear();
        
     
    if(First_Digit==5 && Second_Digit==9){
          First_Digit = First_Digit - 5;
          Second_Digit = Second_Digit -10;
        lcd.print(First_Digit);
  
      
      }
        if(Second_Digit==9){
          First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      Second_Digit = Second_Digit - 10;
          }
        
      }
    }

And the setup and loop are very simple:

void setup()
{
 lcd.begin(16, 2);
}
  
void loop()
{
  Second();
  Minute();
}

I know i can't use delay() and have no idea how to tackle this another way.

My Minute() function is as follows:

void Minute(){

      int First_Digit = 0;
      int Second_Digit = 0;
  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      }
    lcd.setCursor(3, 0);
    lcd.print(First_Digit);
    lcd.setCursor(4, 0);
    lcd.print(Second_Digit);
    delay(60000);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      lcd.print(First_Digit);
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      Second_Digit = Second_Digit - 10;
      }
    
  }
}

And my Second():

    void Second(){
      int First_Digit = 0;
      int Second_Digit = 0;
    
      for(Second_Digit; Second_Digit<10; Second_Digit++){
        if(Second_Digit==10){
          First_Digit = First_Digit + 1;
          }
          
         lcd.setCursor(0, 0);
        lcd.print(First_Digit);
        lcd.setCursor(1, 0);
        lcd.print(Second_Digit);
        delay(1000);
        lcd.clear();
        
        if(First_Digit==5 && Second_Digit==9){
          First_Digit = First_Digit - 5;
          Second_Digit = Second_Digit -10;
          
           }
        if(Second_Digit==9){
          First_Digit = First_Digit + 1;
          Second_Digit = Second_Digit - 10;
          }
        
      }
    }

And the setup and loop are very simple:

void setup()
{
 lcd.begin(16, 2);
}
  
void loop()
{
  Second();
  Minute();
}

I know i can't use delay() and have no idea how to tackle this another way.

My code:

#include <LiquidCrystal.h>
 

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     144
#define btnDOWN   329
#define btnLEFT   504
#define btnSELECT 741
#define btnNONE   5
 

int read_LCD_buttons()
{
 adc_key_in = analogRead(0);    

 if (adc_key_in > 1000) return btnNONE; 
 if (adc_key_in < 50)   return btnRIGHT; 
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;  
 return btnNONE;
 

}
unsigned long minInterval = 60000UL; // Interval for minutes in milliseconds
unsigned long secInterval = 1000UL;  // Interval for seconds in milliseconds
unsigned long prevMinMillis = 0UL;   // Holds the timestamp of the last time Minute() was called
unsigned long prevSecMillis = 0UL;   // Holds the timestamp of the last time Second() was called

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

void loop()
{
  unsigned long currentMillis = millis();

  if (currentMillis - prevMinMillis > minInterval)
  {
    prevMinMillis = currentMillis;
    Minute();
  }

  if (currentMillis - prevSecMillis > secInterval)
  {
    prevSecMillis = currentMillis;
    Second();
  }

}

void Second(){
  int First_Digit = 0;
  int Second_Digit = 0;
  

  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      }
      
    lcd.setCursor(0, 0);
    lcd.print(First_Digit);
    lcd.setCursor(1, 0);
    lcd.print(Second_Digit);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      Second_Digit = Second_Digit - 10;
      }
    
  }
}
void Minute(){
  int First_Digit = 0;
  int Second_Digit = 0;
  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      }
       
    lcd.setCursor(3, 0);
    lcd.print(First_Digit);
    lcd.setCursor(4, 0);
    lcd.print(Second_Digit);
    lcd.clear();
    
     
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      lcd.print(First_Digit);
       
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      Second_Digit = Second_Digit - 10;
      }
    
  }
}
added 228 characters in body
Source Link

My Minute() function is as follows: void Minute(){

void Minute(){

      int First_Digit = 0;
      int Second_Digit = 0;
  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      }
    lcd.setCursor(3, 0);
    lcd.print(First_Digit);
    lcd.setCursor(4, 0);
    lcd.print(Second_Digit);
    delay(60000);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      lcd.print(First_Digit);
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      Second_Digit = Second_Digit - 10;
      }
    
  }
}
    void Second(){
      int First_Digit = 0;
      int Second_Digit = 0;
    
      for(Second_Digit; Second_Digit<10; Second_Digit++){
        if(Second_Digit==10){
          First_Digit = First_Digit + 1;
          }
          
        lcd.setCursor(0, 0);
        lcd.print(First_Digit);
        lcd.setCursor(1, 0);
        lcd.print(Second_Digit);
        delay(1000);
        lcd.clear();
        
        if(First_Digit==5 && Second_Digit==9){
          First_Digit = First_Digit - 5;
          Second_Digit = Second_Digit -10;
          
          }
        if(Second_Digit==9){
          First_Digit = First_Digit + 1;
          Second_Digit = Second_Digit - 10;
          }
        
      }
    }

My Minute() function is as follows: void Minute(){

  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      }
    lcd.setCursor(3, 0);
    lcd.print(First_Digit);
    lcd.setCursor(4, 0);
    lcd.print(Second_Digit);
    delay(60000);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      lcd.print(First_Digit);
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      Second_Digit = Second_Digit - 10;
      }
    
  }
}
void Second(){


  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      }
      
    lcd.setCursor(0, 0);
    lcd.print(First_Digit);
    lcd.setCursor(1, 0);
    lcd.print(Second_Digit);
    delay(1000);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      Second_Digit = Second_Digit - 10;
      }
    
  }
}

My Minute() function is as follows:

void Minute(){

      int First_Digit = 0;
      int Second_Digit = 0;
  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      }
    lcd.setCursor(3, 0);
    lcd.print(First_Digit);
    lcd.setCursor(4, 0);
    lcd.print(Second_Digit);
    delay(60000);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      lcd.print(First_Digit);
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      Second_Digit = Second_Digit - 10;
      }
    
  }
}
    void Second(){
      int First_Digit = 0;
      int Second_Digit = 0;
    
      for(Second_Digit; Second_Digit<10; Second_Digit++){
        if(Second_Digit==10){
          First_Digit = First_Digit + 1;
          }
          
        lcd.setCursor(0, 0);
        lcd.print(First_Digit);
        lcd.setCursor(1, 0);
        lcd.print(Second_Digit);
        delay(1000);
        lcd.clear();
        
        if(First_Digit==5 && Second_Digit==9){
          First_Digit = First_Digit - 5;
          Second_Digit = Second_Digit -10;
          
          }
        if(Second_Digit==9){
          First_Digit = First_Digit + 1;
          Second_Digit = Second_Digit - 10;
          }
        
      }
    }
Source Link

How do i run multiple functions simultaneously on a LCD screen?

I have little to no experience in programming and i'm very slowly and gradually getting the hang of it. My next project is that i'm making a clock, and wanted to use multiple functions for the hour:minute:seconds instead of just using one for everything. But after reading some i came to the conclusion that the arduino can only run one function at a time. So my question is how can i make the illusion of multiple functions running simultaneously on a LCD screen.

My Minute() function is as follows: void Minute(){

  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      }
    lcd.setCursor(3, 0);
    lcd.print(First_Digit);
    lcd.setCursor(4, 0);
    lcd.print(Second_Digit);
    delay(60000);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      lcd.print(First_Digit);
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      lcd.print(First_Digit);
      Second_Digit = Second_Digit - 10;
      }
    
  }
}

And my Second():

void Second(){


  for(Second_Digit; Second_Digit<10; Second_Digit++){
    if(Second_Digit==10){
      First_Digit = First_Digit + 1;
      }
      
    lcd.setCursor(0, 0);
    lcd.print(First_Digit);
    lcd.setCursor(1, 0);
    lcd.print(Second_Digit);
    delay(1000);
    lcd.clear();
    
    if(First_Digit==5 && Second_Digit==9){
      First_Digit = First_Digit - 5;
      Second_Digit = Second_Digit -10;
      
      }
    if(Second_Digit==9){
      First_Digit = First_Digit + 1;
      Second_Digit = Second_Digit - 10;
      }
    
  }
}

And the setup and loop are very simple:

void setup()
{
 lcd.begin(16, 2);
}
  
void loop()
{
  Second();
  Minute();
}

I know i can't use delay() and have no idea how to tackle this another way.