Nothing Clock Document
Arduino Code
#include <DS3231.h>
#include <LiquidCrystal.h>
DS3231 rtc(SDA, SCL);
Time t;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int H,M,S,A,Q,R;
byte bar1[8] =
{
B11100,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11100
};
byte bar2[8] =
{
B00111,
B01111,
B01111,
B01111,
B01111,
B01111,
B01111,
B00111
};
byte bar3[8] =
{
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte bar4[8] =
{
B11110,
B11100,
B00000,
B00000,
B00000,
B00000,
B11000,
B11100
};
byte bar5[8] =
{
B01111,
B00111,
B00000,
B00000,
B00000,
B00000,
B00011,
B00111
};
byte bar6[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte bar7[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00111,
B01111
};
byte bar8[8] =
{
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
void setup()
{
lcd.begin(20, 4);
// assignes each segment a write number
lcd.createChar(1,bar1);
lcd.createChar(2,bar2);
lcd.createChar(3,bar3);
lcd.createChar(4,bar4);
lcd.createChar(5,bar5);
lcd.createChar(6,bar6);
lcd.createChar(7,bar7);
lcd.createChar(8,bar8);
rtc.begin();
//The following lines can be uncommented to set the date and time
//rtc.setDOW(TUESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(10,30, 00); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(13, 12, 2022); // Set the date to January 1st, 2014
}
void custom0(int col)
{ // uses segments to build the number 0
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(8);
lcd.write(1);
lcd.setCursor(col, 2);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}
void custom1(int col)
{
lcd.setCursor(col,1);
lcd.write(32);
lcd.write(32);
lcd.write(1);
lcd.setCursor(col,2);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}
void custom2(int col)
{
lcd.setCursor(col, 1);
lcd.write(5);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 2);
lcd.write(2);
lcd.write(6);
lcd.write(6);
}
void custom3(int col)
{
lcd.setCursor(col,1);
lcd.write(5);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 2);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}
void custom4(int col)
{
lcd.setCursor(col,1);
lcd.write(2);
lcd.write(6);
lcd.write(1);
lcd.setCursor(col, 2);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}
void custom5(int col)
{
lcd.setCursor(col,1);
lcd.write(2);
lcd.write(3);
lcd.write(4);
lcd.setCursor(col, 2);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}
void custom6(int col)
{
lcd.setCursor(col,1);
lcd.write(2);
lcd.write(3);
lcd.write(4);
lcd.setCursor(col, 2);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}
void custom7(int col)
{
lcd.setCursor(col,1);
lcd.write(2);
lcd.write(8);
lcd.write(1);
lcd.setCursor(col, 2);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}
void custom8(int col)
{
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 2);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}
void custom9(int col)
{
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 2);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}
void printNumber(int value, int col) {
if (value == 0) {
custom0(col);
} if (value == 1) {
custom1(col);
} if (value == 2) {
custom2(col);
} if (value == 3) {
custom3(col);
} if (value == 4) {
custom4(col);
} if (value == 5) {
custom5(col);
} if (value == 6) {
custom6(col);
} if (value == 7) {
custom7(col);
} if (value == 8) {
custom8(col);
} if (value == 9) {
custom9(col);
}
}
void loop()
{
t = rtc.getTime();
int d=0;
H=t.hour;
if(H>12)
{
H=H-12;
A=0;
}
else
{
A=1;
}
d=H%10;
printNumber(d, 3);
d=H/10;
printNumber(d, 0);
M=t.min;
d=M%10;
printNumber(d, 10);
d=M/10;
printNumber(d, 7);
S=t.sec;
lcd.setCursor(14, 1);
lcd.print(" ");
lcd.setCursor(14, 2);
lcd.print(S);
lcd.setCursor(14, 1);
if(A){
lcd.print("AM");
}else{
lcd.print("PM");
}
lcd.setCursor(6, 1);
lcd.print(".");
lcd.setCursor(6, 2);
lcd.print(".");
delay(500);
lcd.setCursor(6, 1);
lcd.print(" ");
lcd.setCursor(6, 2);
lcd.print(" ");
delay(500);
if(t.min%2==0)
Q=1;
else
{
Q=0;R=1;
}
if(Q==1&&R==1)
{
lcd.clear();
lcd.setCursor(4, 1);
lcd.print( rtc.getDOWStr());
lcd.setCursor(3, 2);
lcd.print(rtc.getDateStr());
delay(5000);
lcd.clear();
int c=rtc.getTemp();
lcd.setCursor(5, 0);
d=c/10;
printNumber(d, 3);
d=c%10;
printNumber(d,6);
lcd.setCursor(10,1);
lcd.print("o");
lcd.setCursor(11, 2);
lcd.write(2);
lcd.write(3);
delay(5000);
R=0;
}
}
Circuit Diagram For Arduino
Circuit Diagram For PCB
Comments
Post a Comment