Devices & Components
Arduino Uno Rev3
Real Time Clock (RTC)
Catalex digital tube 4-digit Display
Project description
Code
4-digit RTC I2C clock
arduino
Reloj digital mostrado a través de un display de 4 dígitos (digitaltube), y con el tiempo proporcionado por un Tiny RTC de Catalex. Software programado por PentiumCadiz 7-1-17, basado en el ejemplo de la librería DS1307RTC y en el ejemplo de uso del display de Prometec http://www.prometec.net/display-con-interface/
1// Reloj digital mostrado a través de un display de 4 dígitos (digitaltube), y con el tiempo 2// proporcionado por un Tiny RTC de Catalex. 3 4// Software programado por PentiumCadiz 7-1-17, basado en el ejemplo de la librería DS1307RTC 5// y en el ejemplo de uso del display de Prometec http://www.prometec.net/display-con-interface/ 6 7#include <TM1637.h> 8 9#include <Wire.h> 10#include <Time.h> 11#include <DS1307RTC.h> 12 13#define CLK 9 14#define DIO 8 15 16TM1637 Display1(CLK, DIO); 17 int8_t Digitos[] = {0,1,2,3}; 18 int horas; 19 int minutos; 20 boolean alterna; 21 22void setup() { 23 Serial.begin(9600); 24 while (!Serial) ; // wait for serial 25 delay(200); 26 Serial.println("DS1307RTC Read Test"); 27 Serial.println("-------------------"); 28 29 Display1.set(); 30 Display1.init(); 31 32} 33 34void loop() { 35 tmElements_t tm; 36 37 if (RTC.read(tm)) { 38 Serial.print("Ok, Time = "); 39 print2digits(tm.Hour); 40 Serial.write(':'); 41 print2digits(tm.Minute); 42 Serial.write(':'); 43 print2digits(tm.Second); 44 Serial.print(", Date (D/M/Y) = "); 45 Serial.print(tm.Day); 46 Serial.write('/'); 47 Serial.print(tm.Month); 48 Serial.write('/'); 49 Serial.print(tmYearToCalendar(tm.Year)); 50 Serial.println(); 51 52 horas = tm.Hour; 53 minutos = tm.Minute; 54 CalculaDigitos(horas, minutos); 55 if (alterna) 56 { 57 Display1.point(POINT_OFF); 58 alterna = false; 59 } 60 else 61 { 62 Display1.point(POINT_ON); 63 alterna = true; 64 } 65 66 } else { 67 if (RTC.chipPresent()) { 68 Serial.println("The DS1307 is stopped. Please run the SetTime"); 69 Serial.println("example to initialize the time and begin running."); 70 Serial.println(); 71 } else { 72 Serial.println("DS1307 read error! Please check the circuitry."); 73 Serial.println(); 74 } 75 delay(9000); 76 } 77 delay(1000); 78} 79 80void print2digits(int number) { 81 if (number >= 0 && number < 10) { 82 Serial.write('0'); 83 } 84 Serial.print(number); 85} 86 87void CalculaDigitos( int hor, int minu) 88 { 89 int8_t Digit0 = minu %10 ; 90 int8_t Digit1 = (minu % 100) / 10 ; 91 int8_t Digit2 = hor % 10 ; 92 int8_t Digit3 = (hor % 100) / 10 ; 93 94 Digitos[3] = Digit0 ; 95 Digitos[2] = Digit1 ; 96 Digitos[1] = Digit2 ; 97 Digitos[0] = Digit3 ; 98 99 Display1.display(Digitos); 100 } 101
4-digit RTC I2C clock
arduino
Reloj digital mostrado a través de un display de 4 dígitos (digitaltube), y con el tiempo proporcionado por un Tiny RTC de Catalex. Software programado por PentiumCadiz 7-1-17, basado en el ejemplo de la librería DS1307RTC y en el ejemplo de uso del display de Prometec http://www.prometec.net/display-con-interface/
1// Reloj digital mostrado a través de un display de 4 dígitos (digitaltube), y con el tiempo 2// proporcionado por un Tiny RTC de Catalex. 3 4// Software programado por PentiumCadiz 7-1-17, basado en el ejemplo de la librería DS1307RTC 5// y en el ejemplo de uso del display de Prometec http://www.prometec.net/display-con-interface/ 6 7#include <TM1637.h> 8 9#include <Wire.h> 10#include <Time.h> 11#include <DS1307RTC.h> 12 13#define CLK 9 14#define DIO 8 15 16TM1637 Display1(CLK, DIO); 17 int8_t Digitos[] = {0,1,2,3}; 18 int horas; 19 int minutos; 20 boolean alterna; 21 22void setup() { 23 Serial.begin(9600); 24 while (!Serial) ; // wait for serial 25 delay(200); 26 Serial.println("DS1307RTC Read Test"); 27 Serial.println("-------------------"); 28 29 Display1.set(); 30 Display1.init(); 31 32} 33 34void loop() { 35 tmElements_t tm; 36 37 if (RTC.read(tm)) { 38 Serial.print("Ok, Time = "); 39 print2digits(tm.Hour); 40 Serial.write(':'); 41 print2digits(tm.Minute); 42 Serial.write(':'); 43 print2digits(tm.Second); 44 Serial.print(", Date (D/M/Y) = "); 45 Serial.print(tm.Day); 46 Serial.write('/'); 47 Serial.print(tm.Month); 48 Serial.write('/'); 49 Serial.print(tmYearToCalendar(tm.Year)); 50 Serial.println(); 51 52 horas = tm.Hour; 53 minutos = tm.Minute; 54 CalculaDigitos(horas, minutos); 55 if (alterna) 56 { 57 Display1.point(POINT_OFF); 58 alterna = false; 59 } 60 else 61 { 62 Display1.point(POINT_ON); 63 alterna = true; 64 } 65 66 } else { 67 if (RTC.chipPresent()) { 68 Serial.println("The DS1307 is stopped. Please run the SetTime"); 69 Serial.println("example to initialize the time and begin running."); 70 Serial.println(); 71 } else { 72 Serial.println("DS1307 read error! Please check the circuitry."); 73 Serial.println(); 74 } 75 delay(9000); 76 } 77 delay(1000); 78} 79 80void print2digits(int number) { 81 if (number >= 0 && number < 10) { 82 Serial.write('0'); 83 } 84 Serial.print(number); 85} 86 87void CalculaDigitos( int hor, int minu) 88 { 89 int8_t Digit0 = minu %10 ; 90 int8_t Digit1 = (minu % 100) / 10 ; 91 int8_t Digit2 = hor % 10 ; 92 int8_t Digit3 = (hor % 100) / 10 ; 93 94 Digitos[3] = Digit0 ; 95 Digitos[2] = Digit1 ; 96 Digitos[1] = Digit2 ; 97 Digitos[0] = Digit3 ; 98 99 Display1.display(Digitos); 100 } 101
Downloadable files
4-digit RTC I2C clock
A digital clock you can make in a short time.
4-digit RTC I2C clock
Comments
Only logged in users can leave comments