Arduino Tutorial 31# How to make 12 hour format clock (DS1302) with Arduino

Robotica DIY
Robotica DIY
25.3 هزار بار بازدید - 7 سال پیش - Arduino Tutorial 31# How to
Arduino Tutorial 31# How to make 12 hour format clock (DS1302) with Arduino
Scroll down for code.....
Please like & Subscribe for more videos

Real Time Clock (DS1302) library
http://www.rinkydinkelectronics.com/l...

LiquidCrystal_I2C library Github link
https://github.com/fdebrabander/Ardui...

I2C scanner to find out I2C address
http://playground.arduino.cc/Main/I2c...

If you want to support my video please buy any product through my amazon affiliate link. I will receive a commission, at no extra cost to you.

LIST OF COMPONENT (affiliate links)

http://amzn.to/2fvSRJq   (Arduino)
http://amzn.to/2gRFSiv (RTC DS1302)
http://amzn.to/2yBk7eT (LCD display)
http://amzn.to/2zg8aeX (I2C)
http://amzn.to/2wxPmWz  (Breadboard)
http://amzn.to/2vJ3lvo   (Jumper wire)

#include (Wire.h)
#include (LiquidCrystal_I2C.h) //instead of parenthesis () put angle bracket as YouTube description does not allow angle bracket
// Set the LCD address to 0x3F for a 16 chars and 2 line display // note: it may be different for your LCD please find it.
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#include (DS1302.h)
// Init the DS1302
DS1302 rtc(2, 3, 4);
// Init a Time-data structure
Time t;

void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

// The following lines can be commented out to use the values already stored in the DS1302
rtc.setDOW(TUESDAY); // Set Day-of-Week to TUESDAY
rtc.setTime(23, 59, 50); // Set the time to 24hr format it will automatically take time according to AM/PM
rtc.setDate(06, 2, 2018); // Set the date to Febrauray 6th, 2018
// initialize the LCD
lcd.begin();
}

void loop()
{
// Get data from the DS1302
t = rtc.getTime();
lcd.setCursor(0, 0);
if (t.date(=9){
lcd.setCursor(0,0);
lcd.print("0");
lcd.setCursor(1,0);
lcd.print(t.date, DEC);
}
else {
lcd.print(t.date, DEC);}

lcd.setCursor(3, 0);
lcd.print(rtc.getMonthStr());
lcd.setCursor(12,0);
lcd.print(t.year, DEC);
lcd.setCursor(4,1);

{if (t.hour)=12){
lcd.setCursor(13,1);
lcd.print("PM");
lcd.setCursor(4,1);
t.hour = t.hour-12;
if (t.hour== 0) {
t.hour = 12; // Day 12 PM
}
if (t.hour(=9){
lcd.setCursor(4,1);
lcd.print("0");
lcd.setCursor(5,1);
lcd.print(t.hour, DEC);
}
else {
lcd.print(t.hour, DEC);}}
else { if(t.hour==0){
t.hour=12; // Night 12 AM
}
lcd.setCursor(13,1);
lcd.print("AM");
lcd.setCursor(4,1);
if (t.hour(=9){
lcd.setCursor(4,1);
lcd.print("0");
lcd.setCursor(5,1);
lcd.print(t.hour, DEC);
}
else {
lcd.print(t.hour, DEC);}} }
lcd.setCursor(6,1);
lcd.print(":");
lcd.setCursor(7,1);
if (t.min(=9){
lcd.setCursor(7,1);
lcd.print("0");
lcd.setCursor(8,1);
lcd.print(t.min, DEC);
}
else {
lcd.print(t.min, DEC);}

lcd.setCursor(9,1);
lcd.print(":");
lcd.setCursor(10,1);
if (t.sec(=9){
lcd.setCursor(10,1);
lcd.print("0");
lcd.setCursor(11,1);
lcd.print(t.sec, DEC);
}
else {
lcd.print(t.sec, DEC);}
delay (1000);
lcd.clear();
}
7 سال پیش در تاریخ 1396/11/20 منتشر شده است.
25,392 بـار بازدید شده
... بیشتر