amrmostaafaa
Published

Arduino Digital Clock Using 1Sheeld

Monitor the real-time clock on LCD using 1Sheeld board and its companion app.

BeginnerFull instructions provided4,068
Arduino Digital Clock Using 1Sheeld

Things used in this project

Story

Read more

Schematics

Circuit Diagram

Code

Digital_Clock.ino

Arduino
/*
  Arduino Digital Clock Project

  This project shows an application on 1Sheeld's clock shield.

  By using this project, you can monitor the current real time
  by using clock shield from 1Sheeld.
  You can then take certain actions based on the time you get.

  OPTIONAL:
  To reduce the library compiled size and limit its memory usage, you
  can specify which shields you want to include in your sketch by
  defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define.
*/

/* Include clock shield only */
#define CUSTOM_SETTINGS
#define INCLUDE_CLOCK_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* Include LCD library */
#include <LiquidCrystal.h>

/* Define some variables for the time. */
int hour, minute, second;

// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

  /* Start communication. */
  OneSheeld.begin();

  /* Start the clock shield. */
  Clock.queryDateAndTime();

  /* Set up the LCD's number of columns and rows */
  lcd.begin(16, 2);

  /* Print this line to the LCD */
  lcd.print("1Sheeld Clock");
}

void loop() {

  /* Always get the time. */
  hour = Clock.getHours();
  minute = Clock.getMinutes();
  second = Clock.getSeconds();

  /* Set the cursor to column 0, line 1 */
  lcd.setCursor(0, 1);

  /* Print the current hour */
  lcd.print(hour);
  lcd.print(":");

  /* Print the current minute */
  lcd.print(minute);
  lcd.print(":");

  /* Print the current second */
  lcd.print(second);

  /* As once second reaches "59", it start again with "0" not "00" so, the "9" of the previous "59" will stay causing a confusion */
  /* So, we clear the second line after a second has passed */
  if (second == 59)
  {
    delay(100);

    /* Move the cursor to the begining of the second line */
    lcd.setCursor(0, 1);

    /* Loop to clear "print empty spaces" all the 16 places of the second line */
    for (int i = 0; i < 16; i++)
    {
      /* Clear "print empty spaces" to clear the previous time to print a new one */
      lcd.print(" ");
    }
  }
}

Credits

amrmostaafaa

amrmostaafaa

7 projects • 44 followers
Maker, Engineer, dreamer and passionate about technology.

Comments