کد:
#include <Wire.h> // برای راه اندازی این آی سی باید حتما این کتابخونه رو هم فراخونی کنیم
#include <Sodaq_DS3231.h> // فراخوانی کتابخانه این آی سی
DateTime now; // ایجاد یه متغییر از نوع "دیتا تایم"
#include <DS3231.h>
boolean state;
int a;
int yekan=0 ;
int dahgan=0;
int sadgan=0;
int hezargan=0;
int _sec;
int _min;
int _hour;
int h=0;
int m=0;
int s=0;
byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0
{ 0,1,1,0,0,0,0 }, // = 1
{ 1,1,0,1,1,0,1 }, // = 2
{ 1,1,1,1,0,0,1 }, // = 3
{ 0,1,1,0,0,1,1 }, // = 4
{ 1,0,1,1,0,1,1 }, // = 5
{ 1,0,1,1,1,1,1 }, // = 6
{ 1,1,1,0,0,0,0 }, // = 7
{ 1,1,1,1,1,1,1 }, // = 8
{ 1,1,1,0,0,1,1 } // = 9
};
void setup() {
Serial.begin(9600);
// Serial.setTimeout(10);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
DateTime dt(2016, 5, 7, 21, 53, 15, 0);
rtc.setDateTime(dt);
Wire.begin();
rtc.begin();
}
void loop() {
now = rtc.now();
//Serial.print(now.hour());
//Serial.print(':');
//Serial.print(now.minute());
//Serial.print(':');
//Serial.print(now.second());
//Serial.print(" ");
_sec=now.second();
_min=now.minute();
_hour=now.hour();
dahgan=_min/10;
yekan=_min%10;
hezargan=_hour/10;
sadgan=_hour%10;
sevenSegWrite000X(yekan);
delay(50);//20 MILI VAGHEI
sevenSegWrite00X0(dahgan);
delay(50);//20 MILI VAGHEI
sevenSegWrite0X00(sadgan);
delay(50);//20 MILI VAGHEI
sevenSegWriteX000(hezargan);
delay(50);//20 MILI VAGHEI
}
void sevenSegWrite000X(byte digit) {
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
digitalWrite(14, LOW);
digitalWrite(15, LOW);
byte pin = 5;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}
void sevenSegWrite00X0(byte digit) {
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
digitalWrite(14, LOW);
digitalWrite(15, LOW);
byte pin = 5;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}
void sevenSegWrite0X00(byte digit) {
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(14, HIGH);
digitalWrite(15, LOW);
byte pin = 5;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}
void sevenSegWriteX000(byte digit) {
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(14, LOW);
digitalWrite(15, HIGH);
byte pin = 5;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}