Тема: Ретро часы на ИН-16 (Arduino)
Переделка с DS3132 на ds1302
Основная статья - http://rcl-radio.ru/?p=67087
Данный контент доступен только зарегистрированным пользователям.
#include <MsTimer2.h>
#include <iarduino_RTC.h>
#define DS_DAT 11
#define DS_CLK 12
#define SS_RST 13
iarduino_RTC time(RTC_DS1302, SS_RST, DS_CLK, DS_DAT);
int an, segm,times,i;
byte a[4];
void setup(){ time.begin();MsTimer2::set(4, to_Timer);MsTimer2::start();
pinMode(2,OUTPUT); // D2 === H1
pinMode(3,OUTPUT); // D3 === H2
pinMode(4,OUTPUT); // D4 === H3
pinMode(5,OUTPUT); // D5 === H4
pinMode(6,OUTPUT); // D6 === A0 3 ид1
pinMode(7,OUTPUT); // D7 === A1 6 ид1
pinMode(8,OUTPUT); // D8 === A2 7 ид1
pinMode(10,OUTPUT); // D10 === A3 4 ид1
}
void loop(){
time.gettime();
times = time.Hours*100+time.minutes;
a[0]=times/1000;
a[1]=times/100%10;
a[2]=times/10%10;
a[3]=times%10%10;
}
void to_Timer(){
switch(i){
case 0: segm=a[0]; an=0; anod(); segment();delay(1);break;
case 1: segm=a[1]; an=1; anod(); segment();delay(1);break;
case 2: segm=a[2]; an=2; anod(); segment();delay(1);break;
case 3: segm=a[3]; an=3; anod(); segment();delay(1);break;}i++;if(i>3){i=0;}}
void segment(){
switch(segm){
case 0: digitalWrite(10,LOW);digitalWrite(8,LOW);digitalWrite(7,LOW);digitalWrite(6,LOW);break; // DEC 0 = 0b0000
case 1: digitalWrite(10,LOW);digitalWrite(8,LOW);digitalWrite(7,LOW);digitalWrite(6,HIGH);break; // DEC 1 = 0b0001
case 2: digitalWrite(10,LOW);digitalWrite(8,LOW);digitalWrite(7,HIGH);digitalWrite(6,LOW);break; // DEC 2 = 0b0010
case 3: digitalWrite(10,LOW);digitalWrite(8,LOW);digitalWrite(7,HIGH);digitalWrite(6,HIGH);break; // DEC 3 = 0b0011
case 4: digitalWrite(10,LOW);digitalWrite(8,HIGH);digitalWrite(7,LOW);digitalWrite(6,LOW);break; // DEC 4 = 0b0100
case 5: digitalWrite(10,LOW);digitalWrite(8,HIGH);digitalWrite(7,LOW);digitalWrite(6,HIGH);break; // DEC 5 = 0b0101
case 6: digitalWrite(10,LOW);digitalWrite(8,HIGH);digitalWrite(7,HIGH);digitalWrite(6,LOW);break; // DEC 6 = 0b0110
case 7: digitalWrite(10,LOW);digitalWrite(8,HIGH);digitalWrite(7,HIGH);digitalWrite(6,HIGH);break; // DEC 7 = 0b0111
case 8: digitalWrite(10,HIGH);digitalWrite(8,LOW);digitalWrite(7,LOW);digitalWrite(6,LOW);break; // DEC 8 = 0b1000
case 9: digitalWrite(10,HIGH);digitalWrite(8,LOW);digitalWrite(7,LOW);digitalWrite(6,HIGH);break; // DEC 9 = 0b0110
}}
void anod(){
switch(an){
case 0: digitalWrite(2,HIGH);digitalWrite(3,LOW);digitalWrite(4,LOW);digitalWrite(5,LOW);break;
case 1: digitalWrite(2,LOW);digitalWrite(3,HIGH);digitalWrite(4,LOW);digitalWrite(5,LOW);break;
case 2: digitalWrite(2,LOW);digitalWrite(3,LOW);digitalWrite(4,HIGH);digitalWrite(5,LOW);break;
case 3: digitalWrite(2,LOW);digitalWrite(3,LOW);digitalWrite(4,LOW);digitalWrite(5,HIGH);break;
}}