Countdown timer with LCD

I am trying to make a countdown timer with an LCD. As when the countdown timer begins the LCD should display certain messages over the countdown time. I have the countdown clock working but when the LCD displays a message it shuts the clock off.

#include <LiquidCrystal.h>
#include "SevSeg.h"
SevSeg sevseg;

float displayTimeSecs = 0.1; //how long do you want each number on display to show (in secs)
float displayTime = (displayTimeSecs * 5000);
long buzzerFrequency = 500;
float buzzerDuration = (displayTimeSecs * 100);
long startNumber = 1000; //countdown starts with this number
long endNumber = 0; //countdown ends with this number

const int buzzerPin = 52;
const int rs = 22 , en = 23, d4 = 24, d5 = 25, d6 = 26, d7 = 27;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);



void setup() {
  pinMode(buzzerPin,OUTPUT);

  lcd.begin(16,2);

  byte numDigits = 4;
  byte digitPins[] = {10, 11, 12, 13};
  byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};

  
  bool resistorsOnSegments = false;
  byte hardwareConfig = COMMON_CATHODE;
  bool updateWithDelays = false;
  bool leadingZeros = true;
  bool disableDecPoint = true;
  
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
  updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(90);
}


void firstMessage(){
lcd.print("Defuse The Bomb!");
delay(10000);
lcd.setCursor(0,0);
lcd.print("                    ");
  
}

void countdown(){

tone(buzzerPin,buzzerFrequency,buzzerDuration);

if (startNumber >= endNumber) {
        for (long i = 0; i <= displayTime; i++){
          sevseg.setNumber(startNumber,0);
          sevseg.refreshDisplay();
    } 
  startNumber--;
  tone(buzzerPin,buzzerFrequency,buzzerDuration);   
    } 
sevseg.setNumber(0000,0); //after countdown shows endNumber, show this number.
sevseg.refreshDisplay(); 
}

void loop() {

countdown();

if(startNumber <=980){
  firstMessage();
  
}
}

Which board are you using? Mega2560? ESP32?

I see you are using an LCD with SPI, a seven-segment LED with Common Cathode... and a buzzer... are you using these parts? Anything missing? Would you also post a drawing of your project?

Is the same subject?
Do not duplicate topics, it is against the forum rules.

1 Like

Sorry to ask, but where did you find the LCD with SPI?

1 Like

i am using the Mega2560. Yes I am using these parts but also want to include a start and stop button for the countdown. The goal of my project is a bomb timer puzzle. The countdown goes down and while it is going down clues are supposed to display on the LCD.

that was my last post I didn't delete it, i created a new one using the code command because I forgot

Thank you and sorry and... I just learned that I have been incorrectly calling devices using 12 and 11 (MISO/MOSI) as SPI. What is the communication protocol with this LCD called?

(i have been thinking - without exploring - the library was creating the SPI communication on any pins declared in the LCD object creation)

1 Like

I have deleted your other cross-post @brandonv111.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.