Question

HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the...

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.

#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;
      
    }  
  }
    
}

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?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;
    
    }
}
  
}

Add a comment
Know the answer?
Add Answer to:
HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help with this java code supposed to be a military time clock, but I need...

    Need help with this java code supposed to be a military time clock, but I need help creating the driver to test and run the clock. I also need help making the clock dynamic. public class Clock { private int hr; //store hours private int min; //store minutes private int sec; //store seconds public Clock () { setTime (0, 0, 0); } public Clock (int hours, intminutes, int seconds) { setTime (hours, minutes, seconds); } public void setTime (int hours,int...

  • [Java] We have learned the class Clock, which was designed to implement the time of day...

    [Java] We have learned the class Clock, which was designed to implement the time of day in a program. Certain application in addition to hours, minutes, and seconds might require you to store the time zone. Please do the following: Derive the class ExtClock from the class Clock by adding a data member to store the time zone. Add necessary methods and constructors to make the class functional. Also write the definitions of the methods and constructors. Write a test...

  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • This is a Java programming assignment and I want help with the Time class. See below...

    This is a Java programming assignment and I want help with the Time class. See below for assignment details: For this question you must write a java class called Time and a client class called TimeClient. The partial Time class is given below. (For this assignment, you will have to submit 2 .java files: one for the Time class and the other one for the TimeClient class and 2 .class files associated with these .java files. So in total you...

  • Design a way of using the pushbutton to trigger an interrupt to your system. Your system,...

    Design a way of using the pushbutton to trigger an interrupt to your system. Your system, upon receiving this interrupt, responds by reading and displaying the temperature in Fahrenheit degrees on the LCD display in the format of xxx.x. The system must resume displaying the digital clock. Build your circuit and include all the required information about your hardware design in your lab report. 4. Based on the hardware you designed, choose an interrupt/timer tool from mbed to update the...

  • Can someone please help me with the following java assignment. So in this assignment you will...

    Can someone please help me with the following java assignment. So in this assignment you will begin with the starterProject I provide and then add to it.  I am also asking that before you begin you really look at the starterProject because this is the object-oriented basics. The starterProject is the exact same as the ClassClockExample.zip in Module 5.  I’ve also done this using a clock because it is something that you already know how it works.  Remember that OOD and OOP is...

  • Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;   ...

    Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;    minutes = 0;    isAfternoon = false;    //check to make sure there are 5 characters    if (//condition to check if length of string is wrong)    {        cout << "You must enter a valid military time in the format 00:00" << endl;    }    else    {        //check to make sure the colon is in the correct...

  • Linux & C code help with creating a child process and kills itself with SIGNAL. I...

    Linux & C code help with creating a child process and kills itself with SIGNAL. I provided most of the code, I need some help to finish. Please provide output screen shot as well. Thank you! A Process creates a child process. Child process will print out "hello 0" "hello 1" ..... 1 line per second. After a certain number of seconds(user input), it kills itself WITH signal mechanism ONLY, don't use exit() on the child. You can use alarm()...

  • Modify the hours stage of figure 10-18 to keep military time (00-23 hours) SECTION 10-4/DIGITAL CLOCK...

    Modify the hours stage of figure 10-18 to keep military time (00-23 hours) SECTION 10-4/DIGITAL CLOCK PROJECT 763 AMPM tens hrs PM CLRN 74160 units hrs O] QB QC ENT QD ENP RCO units hrs 2] units-hrs[3] CLRN Tens of hours PRN Units of hours CLRN FIGURE 10-18 Detailed circuitry for the HOURS section to count tens of hours. The BCD counter is a 74160, which has two active- HIGH inputs, ENT and ENP, that are ANDed together internally to...

  • I have a program that needs comments added to it: #include <iostream> #include <stdio.h> #include <conio.h>...

    I have a program that needs comments added to it: #include <iostream> #include <stdio.h> #include <conio.h> #include <windows.h> using namespace std; int main() { int m, s,h; cout << "A COUNTDOWN TIMER " << endl; cout << "enter time in hours here" << endl; cin >> h; cout << "enter time in minutes here " << endl; cin >> m; cout << "enter time in seconds here" << endl; cin >> s; cout << "Press any key to start" <<...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT