HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on
ID: 3869682 • Letter: H
Question
HI
C PROGRAMMING
COULD YOU,,
Rewrite the program to have it display the time on the second line of the display, using
the HH:MM:SS format. Use the 24-hour format for the hours, in other words, have the
time go from 00:00:00 to 23:59:59.
1-How would you test the accuracy of the clock you have built? In other words, discuss
how you would test if your clock is counting seconds accurately?
How long would it need to run for you to be confident that it is accurate?
2) In order to test most of the roll over cases (such as 23 hours to 0) to what time would
you initialize your clock, so that you can observe this quickly?
Explanation / Answer
You could check for inaccuracy by starting a stopwatch when you run the program at first.
When the first observable inaccuracy is noted, multiply the time that it took to get that inaccuracy by 10
and record data for that period of time.
#include<LiquidCrystal.h>
LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8);
int minutes = 27; //These global integers keep the value of the clock
int sec = 10;
int hr = 10;
const long interval = 1000; //This interval is equal to 1 second and will be added to seconds
unsigned long oldMillis = 0;
int count;
void setup() {
// put your setup code here, to run once:
LcdDriver.begin(16, 2);
LcdDriver.clear();
LcdDriver.setCursor(0, 0);
}
void loop() {
//LcdDriver.setCursor(0,1);
unsigned long currentMillis = millis();
//This sets up the timer so that it can add one second to the integer
if(currentMillis - oldMillis >= interval) {
oldMillis = currentMillis;
sec++;
LcdDriver.clear();
LcdDriver.setCursor(0, 0);
LcdDriver.print(" Current Time");
LcdDriver.setCursor(4, 1);
if(hr < 10) {
//Prints an extra 0 if hr < 10
LcdDriver.print(0);
LcdDriver.print(hr);
LcdDriver.print(":");
} else {
//Print no zero if hours > 10
LcdDriver.print(hr);
LcdDriver.print(":");
}
if(minutes < 10) {
//Prints an extra 0 if minutes < 10
LcdDriver.print(0);
LcdDriver.print(minutes);
LcdDriver.print(":");
} else {
//Print no zero if minutes > 10
LcdDriver.print(minutes);
LcdDriver.print(":");
}
if(sec < 10) {
//Prints an extra 0 if seconds < 10
LcdDriver.print(0);
LcdDriver.print(sec);
} else {
//Print no zero if seconds > 10
LcdDriver.print(sec);
}
//Adds to minutes whenever seconds is == to 59
if(sec == 59) {
minutes++;
sec = -1;
}
//Adds to hours whenever minutes is == to 59
if(minutes == 60) {
hr++;
minutes = 0;
}
//Resets the clock whenever hours is == to 23
if(hr == 24) {
hr = 0;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.