Help with LCD Counter

Hi, I’m currently attempting to make a simple counter for a class project. Utlimately, it is supposed to count down the hours to Thanksgiving. My partner and I spent a few hours today working on it and made significant progress. However, we discovered that it won’t count down past the minutes. We can’t identify what is causing the glitch. It has to be somwhere in the “if” statements but it it isn’t really standing out. The code is below. Any help would be grealy appreciated. The code is not compelte but we can’t really make any more progress until we figure out the minutes.

#include <LiquidCrystal.h>

int secs1=5;
int secs2=9;
int mins1=0;
int mins2=1;
int hrs1=0;
int hrs2=1;
String colon=":";

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

void setup() {
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Little & Clawson");
  lcd.setCursor(0,1);
  lcd.print("Timers/Counters!");
  delay(2000);
  lcd.clear();
  
}

void loop() {
  
  lcd.setCursor(0, 0);
  lcd.print("CNTDWN TO TRKY!!");
  lcd.setCursor(10,1);
  lcd.print(secs1);
  lcd.setCursor(11,1);
  lcd.print(secs2);
  lcd.setCursor(7,1);
  lcd.print(mins1);
  lcd.setCursor(8,1);
  lcd.print(mins2);
  lcd.setCursor(4,1);
  lcd.print(hrs1);
  lcd.setCursor(5,1);
  lcd.print(hrs2);
  lcd.setCursor(6,1);
  lcd.print(colon);
  lcd.setCursor(9,1);
  lcd.print(colon);
  
  if (secs1>=0 and secs2>0) {
   secs2=secs2-1;
   delay(1000);
  }
  else if (secs2==0 and secs1>0){
    secs2=9;
    secs1=secs1-1;
    delay(1000);
  }
  else if(secs1==0 and secs2==0){
    delay(1000);
    secs1=5;
    secs2=9;
    mins2=mins2-1;
  }
  else if (mins1==0 and mins2==0 and secs1==0 and secs2==0) {
    delay(1000);
    mins1=6;
    mins2=0;
    hrs2=hrs2-1;
  }
  else if (mins1>=0 and mins2>0){
    mins2=mins2-1;
    delay(1000);
  } 
  else if (mins2==0 and mins1>0){
    mins2=9;
    mins1=mins1-1;
    delay(1000);
  }
  else if (hrs1==0 and hrs2==0 and mins1==0 and mins2==0){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.autoscroll();
    lcd.print("Happy Thanksgiving!");  
  } 
}

Right off the bat, your logical "and" in your IF statements is represented as &&, not the word AND.

Also your coding is bad. You don't need secs and secs1 to show the numbers, just do LCD.print(seconds), minutes and hours.

Start at the time you calculated then have seconds start at 59 and just subtract. When seconds reaches 0, subtract one from minute and so on. Don't over complicate it, stick with the basics. You may need a Real Clock timer circuit, to keep the time consistent, and not leave it all to the ARD cycle time , because it takes time to display the numbers and the larger or smaller the number spaces get affect the cycle time.

HazardsMind: Right off the bat, your logical "and" in your IF statements is represented as &&, not the word AND.

Wrong. If Arduino used the C language you would be correct. However, Arduino uses C++ as the base language, and C++ has several alternative keywords to the traditional C operators (you can use either one):

  • and is the same as &&
  • or is the same as ||
  • not is the same as !
  • xor is the same as ^
  • and_eq is the same as &=
  • or_eq is the same as |=
  • not_eq is the same as !=
  • xor_eq is the same as ^=

My apologies, your correct. I've always kept my logics the same, and never used "and" to represent &&. I first started coding in assembler and worked my way up from there, so my logics were always kept the same.

MichaelMeissner:

HazardsMind: Right off the bat, your logical "and" in your IF statements is represented as &&, not the word AND.

Wrong. If Arduino used the C language you would be correct. However, Arduino uses C++ as the base language, and C++ has several alternative keywords to the traditional C operators (you can use either one):

  • and is the same as &&
  • or is the same as ||
  • not is the same as !
  • xor is the same as ^
  • and_eq is the same as &=
  • or_eq is the same as |=
  • not_eq is the same as !=
  • xor_eq is the same as ^=

Thanks for the info. I honestly didn't know that until today.