This code is used to display 2 minute timer on a LCD display but you can also print it on your
serial monitor.
Requirements for the 2 minute timer:
- It should only run once when the code is compiled not ever again
-I tried looking over "Blink without Delay" example and I understood it but I don't know how to apply in my case. Can someone please help?
/* 2 min Countdown timer using liquid crystal display */
// importing library to control display
#include <LiquidCrystal.h>
// importing time library
#include <Time.h>
#define SHUTDOWN_TIMEOUT 120000
unsigned long int previousTime = 0;
int start_time;
// initialize the library by associating with LCD interface pin
// with arduino pin number
const int rs = 11, en = 12, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
twominTimer();
}
// helper method to get 2min timer
int twominTimer() {
char cSec[3];
/* My ATTEMPT to use millis()
while(millis() <= SHUTDOWN_TIMEOUT) {
int minutes = millis() / 6000;
int seconds = millis() % 1000;
Serial.print(minutes);
Serial.print(':');
sprintf(cSec, "%02d", seconds);
Serial.println(cSec);
*/
for (int totalSeconds = 0; totalSeconds <= 120; totalSeconds++) {
int minutes = totalSeconds / 60;
int seconds = totalSeconds % 60
// Print on LCD display
lcd.setCursor(2,1);
lcd.print("Doom bot: ");
lcd.print(minutes);
lcd.print(':');
// lcd.print(seconds);
sprintf(cSec, "%02d", seconds);
lcd.print(cSec);
// print on serial monitor
Serial.print("Doom Boot ");
Serial.print(minutes);
Serial.print(':');
sprintf(cSec, "%02d", seconds);
Serial.println(cSec);
delay(1000); // note - not to use delay*
}