Introduction: Natural Language Clock for RaspberryPi

About: Jack passed away May 20, 2018 after a long battle with cancer. His Instructables site will be kept active and questions will be answered by our son-in-law, Terry Pilling. Most of Jack's instructables are tuto…

All you will need is a RaspberryPi, any model will do.

This program was written to help reacquaint me with string handling in C. The RaspberryPi got me interested in programming again after not doing it in about 20 years.

If you have never used the C compiler included in Raspian now is a good time to try it.

A thank you goes out to PeterO from the RaspberryPi forum for helping me with getting the system time.

    Step 1: Testing

    The program was tested on a 1 GHz model B and on the new model 2B.

    Step 2: The Program

    Copy this program onto your RaspberryPi.

    Compile it with the command: gcc -o clock clock.c

    And run it with the command: ./clock

     * Filename: clock.c
     * A natural language clock program for the RaspberryPi.
     * Compile with the command:
     *   gcc -o clock clock.c
     * Execute with the command: ./clock
    #include <time.h>
    #include <stdio.h>
    #define clrscr() printf("\e[1;1H\e[2J")
    char hours[24][7] = {"Twelve",
    char minutes[60][13] = {"zero",
    char dow[7][10] = {"Sunday","Monday","Tuesday","Wednesday",
    char months[12][10] = {"January","February","March","April",
    char days[32][14] = {"zero",
    struct tm tm2;
    int timeh, timem, times;  // Current hours and minutes and seconds.
    int date, month, year, wday;
     * gettime() function - Loads the current time into the 
     * global variables. It puts the hours in the variable 
     * timeh and the minutes in timem, and so on.
    void gettime()
      time_t now;
      char *str;
      now = time(NULL);                       // Get the time.
      str = ctime(&now);                      // Convert it to a string.
      strptime(str,"%a %b %d %H:%M:%S %Y",&tm2); // Convert from the string version.
      timeh = tm2.tm_hour;                    // Copy hours, minutes and seconds
      timem = tm2.tm_min;                     // into global variables.
      times = tm2.tm_sec;
      date = tm2.tm_mday;
      month = tm2.tm_mon;
      year = tm2.tm_year;
      wday = tm2.tm_wday;
     * dspsec() function - Displays the seconds in the 
     * variable times. Seconds uses the same array as minutes.
    void dspsec(T2)
      if(times>0) printf("and %s seconds ", *minutes+(T2*13));
     * dsptime() function - Clears the screen and displays the 
     * time in natural language. It uses the hours in the
     * variable timeh and the minutes in timem.
    void dsptime()
      int timem2, timeh2, times2; 
      printf("\n\n\n\n\n\n\n\n\n           The time is now:\n");
        case 0:
          printf(           "%s O'clock\n",*hours+(timeh*7));
        case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10:
        case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20:
        case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30:
        case 31: case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40:
        case 41: case 42: case 43: case 44: case 45:
          if(timem==1) printf("           %s minute ",*minutes+(timem*13));
          else printf("           %s minutes ",*minutes+(timem*13));
          printf("past %s o'clock",*hours+(timeh*7));
        case 46: case 47: case 48: case 49: case 50:
        case 51: case 52: case 53: case 54: case 55: case 56: case 57: case 58: case 59:
          timem2 = 60-timem;
          if(timem2==1) printf("           %s minute ",*minutes+(timem2*13));
          else printf("           %s minutes ",*minutes+(timem2*13));
          printf("until %s o'clock",*hours+(timeh*7));
      if(timeh<13) printf(" AM\n");
      else printf(" PM\n");
      printf("           %s, %s %s %d\n\n\n\n\n\n\n", *dow+(wday*10), *months+(month*10), *days+(date*14) ,(1900+year));
     * main() function
      int ptime = 70; // previous time after gettime()
        if(ptime != times)
          ptime = times;


    Raspberry Pi Contest

    Participated in the
    Raspberry Pi Contest