Countdown timer 16x2 lcd

I know, but this is short code so no need to make it more compact, it works fine

shouldn't there be a test for zero when MinutesRemaining is decremented to determine when the timer has expired?

what do you mean

you mean this?

do you want the timer to go past 0?

this makes it stop at 00:00

that turns turns the buzzer on

what stops if from coninueing to count?

does it matter? since it clears the lcd so it won't be displayed again

what prevents it from going past zero?

I dont get the problem, does it matter that it goes past zero?

won't the be displayed?

is this the behavior you're satisfied with

it doesn't get displayed, no, but 65535:60 does for some reason and i dont know why

what is the max value of a 16-bit unsigned integer?

what is the value of an unsigned integer with a value of zero that is decremented by 1?

Ok i get it, its counting 0 down to one and displaying the max value of an integer, right?


what prevents your code from setting MinutesRemaining and SecondsRemaining each iteration of loop() when a keyVal matches?

why do you think this restarts the timer?

Can you give me an example of what I need to do?


#define MyHW
#ifdef MyHW
# include "sim.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(6, 7, 8, 9, 10, 11, 12);
int backLight = 13; // pin 13 will control the backlight

byte pinBut = A1;

unsigned long previousMillis = 0;
unsigned int seconds;
byte         butLst;

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin (9600);

    pinMode      (backLight, OUTPUT);
    digitalWrite (backLight, HIGH);

    pinMode      (pinBut,    INPUT_PULLUP);
    butLst = digitalRead (pinBut);

    lcd.begin(16, 2);
    lcd.write("Select your time");

// -----------------------------------------------------------------------------
void loop()
    unsigned long currentMillis = millis();

    if (seconds)  {
        if (currentMillis - previousMillis >= 1000) {
            previousMillis += 1000;


            char s [20];
            sprintf (s, " %02d:%02d", seconds / 60, seconds % 60);

            if (seconds == 0) {
                tone(5, 523, 2000);
                tone(5, 400, 2000);

    byte but = digitalRead (pinBut);
    if (butLst != but)  {
        butLst = but;
        delay (10);     // deounce

        if (LOW == but)
            seconds += 15 * 60;
        previousMillis = currentMillis;

I can´t find sim.h library, can you link it?


change "#define" to "#undef"