Good day,
I got my first Arduino Uno yesterday and got a 16x2 LCD hooked up and working okay.
My problem is this: I tried to write an extremely simple countdown timer from 30 seconds down to zero.
For the most part it works. I dont need it to be 100% accurate but just countdown, and on zero, stop the countdown and display other text. It does the countdown and on zero displays other text, but continues to count into negative digits over the text. How do I get it to stop at zero or at least appear that that what its done.
I understand that void has no "end result", but what is the work around this? Here is my noob code
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int time=30; //Entire variable declaration(time)
void setup()
{
lcd.begin(16, 2); //LCD begins. dimension: 16x2(Coluns x Rows)
lcd.setCursor(0, 0); // Positions the cursor in the first column (0) and the firt row (1) at LCD
lcd.print("Countdown"); //LCD write comand
lcd.setCursor(0, 1); // Positions the cursor in the first column (0) and the second row (1) at LCD
lcd.print("Testing"); // LCD write command
}
void loop(){
lcd.setCursor(13, 1); // Positions the cursor on the fourteenth column (13) and the second line (1) LCD
lcd.print(" "); // Write the current value of the count variable in the LCD
lcd.setCursor(13, 1); // Positions the cursor on the fourteenth column (13) and the second line (1) LCD
lcd.print(time); // Write the current value of the count variable in the LCD
delay(1000); // Waits for 1 second
time--; // Decrement count variable
if(time == 0)
{
lcd.setCursor(0, 1); // Positions the cursor on the fourteenth column (13) and the second line (1) LCD
lcd.print("Thanks. Time Up!"); // Write the current value of the count variable in the LCD
}
}
Can anybody point me in the right direction?
Thanks in advance for your help. Much appreciated!