Friday, March 27, 2015

It's a Clock !


I've got the basic clock sending time output to the displays.  The LEDs show who is on move, and the buttons switch the clocks and LEDs.



What is left to do (software):
- move counter
- increment and delay
- multiple periods
- Setup routine for setting time and choosing options using buttons
- save settings to non-volatile memory

What is left to do (hardware)
- switches (on/off and pause)
- 4 buttons for navigating the menus
- prototype case, probably plastic
- eventually a nice wooden case, with mechanical plungers.


Sketch Update

I modified the printTime() function to convert the time remaining for each player from 1/10 seconds to H:MM:SS and to write that to the displays, by calling a new writeNum() function.


// Function to write the time to the displays
void printTime() {                      // print time function
  int secDis1;
  int secDis10;
  int minDis1;
  int minDis10;
  int hrDis1;
  int secs;
  
  secs = timeR1 / 10;                  // convert 1/10 sec to H:MM:SS
  hrDis1 = secs / 3600;
  secs = secs % 3600;
  minDis10 = secs / 600;
  secs = secs % 600;
  minDis1 = secs / 60;
  secs = secs % 60;
  secDis10 = secs / 10;
  secDis1 = secs % 10;
  
  writeNum(hrDis1,3,1);
  writeNum(minDis10,7,1);
  writeNum(minDis1,10,1);
  writeNum(secDis10,14,1);
  writeNum(secDis1,17,1);
  
  secs = timeR2 / 10;                  // convert 1/10 sec to H:MM:SS
  hrDis1 = secs / 3600;
  secs = secs % 3600;
  minDis10 = secs / 600;
  secs = secs % 600;
  minDis1 = secs / 60;
  secs = secs % 60;
  secDis10 = secs / 10;
  secDis1 = secs % 10;
  
  writeNum(hrDis1,3,2);
  writeNum(minDis10,7,2);
  writeNum(minDis1,10,2);
  writeNum(secDis10,14,2);
  writeNum(secDis1,17,2); 
}




Part of the writeNum() function:




// function to write digits to the displays
void writeNum(int charDigit, int charPos, int turn){
   switch (charDigit){
      case 0:
         if (turn==1){
           lcd1.setCursor(charPos,0);
           lcd1.write(1);
           lcd1.write(2);
           lcd1.write(2);
           lcd1.setCursor(charPos,1);
           lcd1.write(3);
           lcd1.write(32);
           lcd1.write(3);
           lcd1.setCursor(charPos,2);
           lcd1.write(3);
           lcd1.write(32);
           lcd1.write(3);
           lcd1.setCursor(charPos,3);
           lcd1.write(3);
           lcd1.write(2);
           lcd1.write(4);
         }
         else{
           lcd2.setCursor(charPos,0);
           lcd2.write(1);
           lcd2.write(2);
           lcd2.write(2);
           lcd2.setCursor(charPos,1);
           lcd2.write(3);
           lcd2.write(32);
           lcd2.write(3);
           lcd2.setCursor(charPos,2);
           lcd2.write(3);
           lcd2.write(32);
           lcd2.write(3);
           lcd2.setCursor(charPos,3);
           lcd2.write(3);
           lcd2.write(2);
           lcd2.write(4); 
         }
         break;

and this continues for each of the 10 digits, plus a blank space if I want to use that later.

No comments:

Post a Comment