ไลบรารี Arduino เพื่อตรวจสอบวันที่และอุณหภูมิของ DS3231 ในตัวผ่าน I2C
อัปเดต: เยี่ยมชมใหม่ด้วย ไลบรารี่เพื่อจัดการวันที่และเวลาด้วยโมดูล DS3231 RTC และ Arduino ด้วยการปรับปรุงเช่นเวลาตามฤดูกาล
การทำงานของ IC de นาฬิกาเรียลไทม์ (RTC) ยอดนิยมที่ถูกควบคุมโดยใช้ รถบัสฉัน2C มักจะคล้ายกันมาก นอกจากนี้ ห้องสมุดลวด de แพลตฟอร์มฮาร์ดแวร์ ช่วยลดความยุ่งยากในการสื่อสารกับอุปกรณ์อย่างมาก อินเทอร์เฟซแบบอนุกรมสองสาย (TWI), I2C, เฉพาะเจาะจง.
กล่าวโดยกว้างๆ กระบวนการประกอบด้วย
-
เริ่มต้นการสื่อสารแบบสลาฟหรือมาสเตอร์ (ตั้งค่าตามค่าเริ่มต้น) ด้วยฟังก์ชัน Wire.begin(ที่อยู่). หากละเว้น "ที่อยู่" การสื่อสารจะเริ่มต้นด้วย ไมโครซี ครูของ รถบัสฉัน2C.
-
เปิดใช้งานการสื่อสาร I2C กับอุปกรณ์ผ่านที่อยู่หน่วยความจำที่อุปกรณ์นั้นตั้งอยู่โดยใช้คำสั่ง Wire.beginTransmission (ที่อยู่).
-
เขียนคำสั่งใน รถบัสฉัน2C เพื่อบอกอุปกรณ์ถึงการทำงานที่คุณต้องการให้ดำเนินการโดยใช้ Wire.write (คำสั่ง)โดยที่ "order" คือรหัสการดำเนินการ
-
ปิดการใช้งานการสื่อสารเพื่อเผยแพร่ รถบัสฉัน2C ด้วยฟังก์ชั่น Wire.endTransmission ().
-
ขอให้อุปกรณ์ส่งข้อมูลจำนวนหนึ่งให้สอดคล้องกับการดำเนินการที่ได้รับการร้องขอ (ในกรณีนี้คือวันที่และเวลา) ด้วยฟังก์ชัน Wire.requestFrom(ที่อยู่,จำนวนเงิน).
-
รอให้ข้อมูลที่ร้องขอด้วยฟังก์ชันพร้อมสำหรับการอ่าน Wire.available ()ซึ่งส่งคืนจำนวนข้อมูลที่ได้รับแล้วและสามารถอ่านได้
-
อ่านข้อมูลที่ส่งมาจากอุปกรณ์ (ไฟล์ นาฬิกาเรียลไทม์ในกรณีนี้) โดยใช้ฟังก์ชัน Wire.read() หลายครั้งตามจำนวนไบต์ที่ระบุ Wire.available () ที่มีอยู่
-
โดยปกติข้อมูลจะถูกส่งในรูปแบบที่กะทัดรัดมากดังนั้นจึงมีความเป็นไปได้มากที่จะต้องตีความข้อมูลที่ได้รับในลักษณะที่สอดคล้องกับการแสดงข้อมูลที่จัดทำในโปรแกรมที่ใช้อุปกรณ์
เกี่ยวกับ DS3231 (และรุ่นที่รองรับในซีรีย์เดียวกัน เช่น DS3232) และการตีความข้อมูลตามข้อกำหนดของการบูรณาการ เช่น ค่าของตัวเลขต่าง ๆ ที่แสดงถึงเวลาจะแสดงเป็น ทศนิยมรหัสไบนารี (BCD) ซึ่งจะสะดวกกว่าในการแสดงเป็นค่าทศนิยม (ก ไบต์) เพื่อใช้ใน แพลตฟอร์มฮาร์ดแวร์
ในบรรทัดเดียวกัน อุณหภูมิจะแสดงเป็นไบต์ในหน่วย ส่วนเสริมของสอง สำหรับส่วนจำนวนเต็มและสองบิตสำหรับขั้นตอนที่มีความละเอียดหนึ่งในสี่ของดีกรีของส่วนทศนิยม ลักษณะเหล่านี้และลักษณะอื่น ๆ ของการแสดงข้อมูลบนนาฬิกามีการพูดคุยอย่างละเอียดถี่ถ้วนในรหัสห้องสมุดด้านล่าง DS3231
หากต้องการตรวจสอบอุณหภูมิด้วยไลบรารีนี้ เพียงใช้วิธีการ อ่าน_อุณหภูมิ() วัตถุ DS3231 เกิดขึ้นตั้งแต่ต้น หากต้องการอ่านวันที่และเวลา ขั้นแรกให้โหลดแล้วร้องขอในรูปแบบใดรูปแบบหนึ่ง (กะทัดรัด มนุษย์...) ที่พร้อมใช้งานสำหรับการใช้งานที่แตกต่างกัน โดยบันทึกไว้ในเอกสารส่วนหัวของไลบรารีโค้ดด้านล่าง
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
//DS3231.h
#if defined(ARDUINO) && ARDUINO>=100
#include “Arduino.h”
#else
#include “WProgram.h”
#endif
#include <Wire.h>
#define TEMPERATURA_MAXIMA_DS3231 85.0 // Máxima temperatura que se puede medir con un DS3231 (70 grados en la versión comercial / no-industrial)
#define TEMPERATURA_MINIMA_DS3231 -40.0 // Mínima temperatura que se puede medir con un DS3231 (0 grados en la versión comercial / no-industrial)
#define DIRECCION_DS3231 B1101000 // Según datasheet
#define TIMEOUT_I2C_DS3231 200 // Máximo tiempo de espera del bus I2C del DS3231
#define NUMERO_ELEMENTOS_FECHA 7 // Número de elementos (un byte por elemento) que tiene la matriz con los datos de la fecha
#define NUMERO_BYTES_TEMPERATURA 2 // Número de bytes con los que se representa la temperatura (uno para la parte entera y el signo y otro para la parte decimal representada con una resolución de 0.25 grados)
#define RESOLUCION_DECIMALES_DS3231 0.25 // Grados de cada paso de la parte decimal
#define ROTACION_DECIMALES 6 // Rotación necesaria hasta llegar a los bits que contienen la parte que representa los decimales de la temperatura (rotar 6 corresponde a atender a los bits 7 y 8)
#define MASCARA_DECIMALES B11000000 // Máscara para eliminar con una operación and la parte no significativa. En el caso el DS3231 no hace nada ya que al rotar queda sólo la parte relevante.
class DS3231
{
private:
char valor_fecha_hora_DS3231[7]; // Matriz de valores numéricos (7 char) de la fecha y la hora. El índice 0 representa los segundos, el 1 los minutos, el 2 las horas (en formato de 24), el 3 el día de la semana empezando en el domingo que es 1, el 4 el día del mes, el 5 el número del mes y el 6 los dos últimos dígitos del año
char hora_humana_DS3231[11]; // Hora en el formato hh:mm:ss siendo hh la hora (en formato de 24) representada con 2 dígitos, mm los minutos con 2 dígitos y ss los segundos con 2 dígitos
char fecha_humana_DS3231[11]; // Fecha en formato DD/MM/AAAA siendo DD el día representado con 2 dígitos, MM el mes con 2 dígitos y AAAA el año con 4 dígitos
char fecha_hora_MySQL_DS3231[20]; // Fecha en formato AAAA-MM-DD hh:mm:ss (estilo MySQL) siendo AAAA el año representado con 4 dígitos, MM el mes con 2 dígitos, DD el día con 2 dígitos, hh la hora (en formato de 24) con 2 dígitos, mm los minutos con 2 dígitos y ss los segundos con 2 dígitos
char fecha_hora_compacta_DS3231[13]; // Fecha en formato compacto (como la anterior pero sin adornos y dos dígitos para el año) para escribir en log y en bases de datos
char bcd_a_decimal(char bcd); // Convertir de BCD a decimal
char decimal_a_bcd(char decimal); // Convertir de decimal a BCD
protected:
public:
DS3231();
~DS3231();
void cargar_fecha_hora();
void grabar_fecha_hora(char *fecha);
char *valor_fecha_hora();
char *hora_humana(); // Hora en el formato hh:mm:ss siendo hh la hora (en formato de 24) representada con 2 dígitos, mm los minutos con 2 dígitos y ss los segundos con 2 dígitos
unsigned int reloj_4_digitos_7_segmentos(); // La hora tal como la esperan la mayoría de relojes de cuatro dígitos LED de 7 segmentos
char *fecha_humana(); // Fecha en formato DD/MM/AAAA siendo DD el día representado con 2 dígitos, MM el mes con 2 dígitos y AAAA el año con 4 dígitos
char numero_dia_semana(); // Eso y empezando en domingo que es el 1
char *fecha_hora_MySQL(); // Fecha en formato AAAA-MM-DD hh:mm:ss (estilo MySQL) siendo AAAA el año representado con 4 dígitos, MM el mes con 2 dígitos, DD el día con 2 dígitos, hh la hora (en formato de 24) con 2 dígitos, mm los minutos con 2 dígitos y ss los segundos con 2 dígitos
char *fecha_hora_compacta(); // Fecha en formato compacto (como la anterior pero sin adornos y dos dígitos para el año) para escribir en log y en bases de datos
double leer_temperatura();
double temperatura_minima();
double temperatura_maxima();
};
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
//DS3231.cpp
#include “DS3231.h”
DS3231::DS3231()
{
//Wire.begin(); // Dependiendo de la versión del IDE puede ser maestro por defecto o no y habrá que activar en la librería o en la aplicación que la use (en el ejemplo se activa desde la aplicación, lo que permite un uso más genérico)
}
DS3231::~DS3231()
{
}
void DS3231::cargar_fecha_hora()
{
unsigned long timeout_i2c;
byte contador;
Wire.beginTransmission(DIRECCION_DS3231); // Comunicar con el DS3231 en la dirección correspondiente
Wire.write(0x00); // pedir registros desde la primera dirección
Wire.endTransmission(); // Liberar el bus I2C
Wire.requestFrom(DIRECCION_DS3231,NUMERO_ELEMENTOS_FECHA); // esperar NUMERO_ELEMENTOS_FECHA bytes
timeout_i2c=millis()+TIMEOUT_I2C_DS3231;
while(Wire.available()<NUMERO_ELEMENTOS_FECHA&&millis()<timeout_i2c){} // Esperar a que lleguen los datos o a que pase el tiempo mínimo de espera // Para usar sin espera: if(Wire.available())
for(contador=0;contador<NUMERO_ELEMENTOS_FECHA;contador++)
{
valor_fecha_hora_DS3231[contador]= Wire.read(); // Leer todos los datos sin discriminar aunque luego tendrán distinto tratamiento
}
valor_fecha_hora_DS3231[0]=bcd_a_decimal(valor_fecha_hora_DS3231[0]); // segundos en BCD
valor_fecha_hora_DS3231[1]=bcd_a_decimal(valor_fecha_hora_DS3231[1]); // minutos en BCD
valor_fecha_hora_DS3231[2]=((valor_fecha_hora_DS3231[2]&B00110000)>>4)*10+(valor_fecha_hora_DS3231[2]&B00001111); // BCD en modo de 24 horas
valor_fecha_hora_DS3231[3]=valor_fecha_hora_DS3231[3]&B00000111; // Número de día de la semana empezando en 1 que es domingo
valor_fecha_hora_DS3231[4]=((valor_fecha_hora_DS3231[4]&B00110000)>>4)*10+(valor_fecha_hora_DS3231[4]&B00001111); // Número del día del mes
valor_fecha_hora_DS3231[5]=((valor_fecha_hora_DS3231[5]&B00010000)>>4)*10+(valor_fecha_hora_DS3231[5]&B00001111); // Número de mes (sin MSB)
valor_fecha_hora_DS3231[6]=bcd_a_decimal(valor_fecha_hora_DS3231[6]); // Año en BCD (dos últimos dígitos)
}
char *DS3231::valor_fecha_hora()
{
//cargar_fecha_hora();
return valor_fecha_hora_DS3231;
}
char *DS3231::hora_humana()
{
//cargar_fecha_hora();
sprintf
(
hora_humana_DS3231,
“%02d:%02d:%02d”,
valor_fecha_hora_DS3231[2],
valor_fecha_hora_DS3231[1],
valor_fecha_hora_DS3231[0]
);
return hora_humana_DS3231;
}
unsigned int DS3231::reloj_4_digitos_7_segmentos()
{
//cargar_fecha_hora();
return (int)valor_fecha_hora_DS3231[2]*100+(int)valor_fecha_hora_DS3231[1];
}
char *DS3231::fecha_humana()
{
//cargar_fecha_hora();
sprintf
(
fecha_humana_DS3231,
“%02d/%02d/20%02d”, // Formato de fecha y hora estilo español ¡Olé!
valor_fecha_hora_DS3231[4],
valor_fecha_hora_DS3231[5],
valor_fecha_hora_DS3231[6]
);
return fecha_humana_DS3231;
}
char DS3231::numero_dia_semana()
{
//cargar_fecha_hora();
return valor_fecha_hora_DS3231[3];
}
char *DS3231::fecha_hora_compacta()
{
//cargar_fecha_hora();
sprintf
(
fecha_hora_compacta_DS3231,
“%02d%02d%02d%02d%02d%02d”, // Formato de fecha y hora compacta para log y base de datos
valor_fecha_hora_DS3231[6],
valor_fecha_hora_DS3231[5],
valor_fecha_hora_DS3231[4],
valor_fecha_hora_DS3231[2],
valor_fecha_hora_DS3231[1],
valor_fecha_hora_DS3231[0]
);
return fecha_hora_compacta_DS3231;
}
char *DS3231::fecha_hora_MySQL()
{
//cargar_fecha_hora();
sprintf
(
fecha_hora_MySQL_DS3231,
“20%02d-%02d-%02d %02d:%02d:%02d”, // Formato de fecha y hora estilo MySQL
valor_fecha_hora_DS3231[6],
valor_fecha_hora_DS3231[5],
valor_fecha_hora_DS3231[4],
valor_fecha_hora_DS3231[2],
valor_fecha_hora_DS3231[1],
valor_fecha_hora_DS3231[0]
);
return fecha_hora_MySQL_DS3231;
}
void DS3231::grabar_fecha_hora(char *fecha)
{
byte contador;
Wire.beginTransmission(DIRECCION_DS3231); // Comunicar con el DS3231 en la dirección correspondiente
Wire.write(0x00); // Empezar el envío en la primera dirección
for(contador=0;contador<NUMERO_ELEMENTOS_FECHA;contador++)
{
Wire.write(decimal_a_bcd(fecha[contador])); // Escribir cada valor expresándolo en BCD
}
Wire.endTransmission(); // Liberar el bus I2C
}
double DS3231::leer_temperatura()
{
byte msb; // El byte más significativo contiene la parte entera de la temperatura (en complemento a 2 para poder representar temperaturas bajo cero)
byte lsb; // El byte menos significatico contiene la parte decimal con una resolución de un cuarto de grado
float temperatura=TEMPERATURA_MAXIMA_DS3231+1.0; // Un número mayor que el máximo como aviso de que algo va mal
boolean negativo=false; // Inicialmente se considera postivo
unsigned long timeout_i2c;
Wire.beginTransmission(DIRECCION_DS3231); // Preparar el dispositivo
Wire.write(0x11); // Solicitar temperatura (empieza en 11h y termina en 12h)
Wire.endTransmission();
Wire.requestFrom(DIRECCION_DS3231,NUMERO_BYTES_TEMPERATURA); // Esperar temperatura: pedir dos bytes en la dirección del integrado
timeout_i2c=millis()+TIMEOUT_I2C_DS3231;
while(Wire.available()<NUMERO_BYTES_TEMPERATURA&&millis()<timeout_i2c){}// Esperar a que lleguen los datos o pase el tiempo de espera máximo // Para usar sin espera: if(Wire.available())
msb=Wire.read(); // parte entera con signo en complemento a dos
lsb=Wire.read(); // parte fraccional con resolución de 0.25 grados
negativo=msb>B01111111; // Es negativo si el primer dígito es uno
temperatura=msb&B01111111; // revertir complemento a dos
temperatura+=((lsb&MASCARA_DECIMALES)>>ROTACION_DECIMALES)*RESOLUCION_DECIMALES_DS3231; // atender sólo a los bits que contienen la parte decimal (7 y 8), multiplicar por el paso de la resolución y sumar a la parte entera de la temperatura
if(negativo)
{
temperatura*=–1; // Cambiar el signo
}
return temperatura;
}
double DS3231::temperatura_minima()
{
return TEMPERATURA_MINIMA_DS3231;
}
double DS3231::temperatura_maxima()
{
return TEMPERATURA_MAXIMA_DS3231;
}
char DS3231::bcd_a_decimal(char bcd) // Convertir de BCD a decimal
{
return ((bcd&B11110000)>>4)*10+(bcd&B00001111);
}
char DS3231::decimal_a_bcd(char decimal) // Convertir de decimal a BCD
{
return decimal/10*16+(decimal%10);
}
|
ต่อไปนี้เป็นโค้ดตัวอย่างเพื่อแสดงวิธีการใช้ไลบรารี ตามที่กล่าวไว้ข้างต้น อุณหภูมิจะอ่านได้ง่ายๆ ด้วยฟังก์ชัน
ของวัตถุคลาส แต่เพื่อละเว้นข้อผิดพลาดในการอ่าน จะใช้ค่าคงที่สองตัวเพื่อจัดเก็บอุณหภูมิสูงสุดและต่ำสุดของอุปกรณ์ตามลำดับตามแผ่นข้อมูล และค่าที่อ่านด้วยฟังก์ชันที่เกี่ยวข้องกันการอ่านอุณหภูมิดำเนินการในสองขั้นตอน: ขั้นแรกโหลดค่า เพื่อให้การใช้วันที่หรือเวลาที่แตกต่างกันมีความสอดคล้องกัน (จะไม่แสดงค่าที่สูงกว่าในกรณีที่ไม่เอื้ออำนวย) และประการที่สองจะใช้ตามรูปแบบที่ มันจำเป็น. โปรแกรมตัวอย่าง (ซึ่งไม่ค่อยมีประโยชน์นัก แม้ว่าจะอธิบายความเป็นไปได้ทั้งหมดก็ตาม) จะแสดงรูปแบบที่มีอยู่ทั้งหมด
-
ฟังก์ชั่น ถัง (ไบต์) ที่มีค่าตัวเลขเจ็ดค่าที่แสดงวันที่และเวลาบนนาฬิกา DS3231 แปลงเป็นทศนิยม (อยู่ใน BCD บนอุปกรณ์)
ซึ่งส่งกลับตัวชี้ไปยังอาร์เรย์ -
การใช้ฟังก์ชั่น
ได้รับค่าที่สอดคล้องกับจำนวนวันในสัปดาห์ที่เริ่มต้นในวันอาทิตย์ หากต้องการแสดงเป็นข้อความ จะใช้อาร์เรย์และลบออกหนึ่งรายการเพื่อเริ่มต้นที่ดัชนีศูนย์ในวันอาทิตย์ -
หากต้องการดูวันที่ในรูปแบบ "ท้องถิ่น" (สเปน) ให้ใช้ฟังก์ชัน
ซึ่งส่งคืนตัวชี้ไปยังสตริงที่แสดงวันที่ในรูปแบบ DD/MM/YYYY โดยที่ DD คือวันที่แสดงด้วยตัวเลข 2 หลัก MM คือเดือนที่มี 2 หลัก และ YYYY คือปีที่มี 4 หลัก -
ฟังก์ชั่น
ส่งคืนเวลาในรูปแบบ hh:mm:ss โดย hh เป็นชั่วโมง (ในรูปแบบ 24) แทนด้วยตัวเลข 2 หลัก mm เป็นนาทีที่มี 2 หลัก และ ss เป็นวินาทีที่มี 2 หลัก -
เพื่อให้ง่ายต่อการใช้งานวันที่และเวลา ไฟล์บันทึก ฟังก์ชั่นได้รับการตั้งโปรแกรมไว้แล้ว โดยส่งค่าวันที่และเวลาในรูปแบบ YYMMDDhhmmss โดย AA คือปีแสดงด้วยตัวเลข 2 หลักสุดท้าย MM เดือนมี 2 หลัก DD วันมี 2 หลัก hh ชั่วโมง (ในรูปแบบ 24) ด้วย 2 หลัก มิลลิเมตร นาทีที่มี 2 หลัก และ ss วินาทีที่มี 2 หลัก รูปแบบนี้แม้จะเป็นข้อความ แต่ก็ใช้พื้นที่น้อยและทำให้สามารถเรียงลำดับตัวอักษรได้ง่ายมาก
-
ฟังก์ชั่น MySQL (หรือใหม่และอิสระกว่า MariaDB) YYYY-MM-DD hh:mm:ss โดยที่ YYYY คือปีที่แสดงด้วยตัวเลข 4 หลัก, MM คือเดือนที่มีตัวเลข 2 หลัก, DD คือวันที่มีตัวเลข 2 หลัก, hh คือชั่วโมง (ในรูปแบบ 24 หลัก) มี 2 หลัก , mm คือนาทีที่มี 2 หลัก และวินาทีที่มี 2 หลัก
ทำหน้าที่นำเสนอวันที่และเวลาในรูปแบบที่ผู้จัดการฐานข้อมูลใช้
แม้ว่าจะมีหลายรูปแบบที่ใช้แสดงวันที่และเวลา แต่รูปแบบที่คุณต้องการอาจไม่มีอยู่ แต่แน่นอนว่าขึ้นอยู่กับรูปแบบใดรูปแบบหนึ่งที่มีอยู่และใช้เป็นตัวอย่าง จะทำให้ง่ายต่อการเพิ่มวิธีการใหม่ตาม ข้อกำหนดอื่น ๆ กรุณาถ้าคุณเพิ่มฟังก์ชั่นใหม่ แบ่งปันโค้ด (ปล่อยมัน!) และอธิบายให้เราฟังว่ามันทำงานอย่างไร เพื่อที่เราจะได้สามารถทำให้ห้องสมุดดีขึ้นทีละน้อย ขอบคุณ!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#define INTERVALO_MEDICION 100000 // Medir temperatura cada 100 segundos (se renueva internamente en el DS3231 cada 64 segundos)
#define ESPERA_ERROR 1000 // Tiempo de espera antes de volver a medir si se ha producido un error
#define ELEMENTOS_MATRIZ_FECHA 7
#include “DS3231.h”
#include <Wire.h>
char buffer_fecha[ELEMENTOS_MATRIZ_FECHA];
char *puntero_fecha;
float temperatura;
unsigned long cronometro;
byte contador;
String dia_semana[]={“lunes”,“martes”,“miércoles”,“jueves”,“viernes”,“sábado”,“domingo”};
DS3231 reloj;
void setup()
{
Serial.begin(9600);
Wire.begin(); // Inicializar Wire sólo si no se hace dentro del constructor (de la librería) Este método, hacerlo en la aplicación, supone que se usa Wire para comunicar con otros dispositivos, no sólo con el DS3231
cronometro=0; // para que empiece inmediatamente
}
void loop()
{
if(millis()>cronometro)
{
temperatura=reloj.leer_temperatura();
if(temperatura>reloj.temperatura_maxima()||temperatura<reloj.temperatura_minima())
{
cronometro=millis()+ESPERA_ERROR;
}
else
{
cronometro=millis()+INTERVALO_MEDICION;
reloj.cargar_fecha_hora();
puntero_fecha=reloj.valor_fecha_hora();
for(contador=0;contador<ELEMENTOS_MATRIZ_FECHA;contador++)
{
buffer_fecha[contador]=*(puntero_fecha+contador);
Serial.println(“Contenido de la posición “+String(contador,DEC)+” del buffer de la fecha -> “+String(int(buffer_fecha[contador]),DEC));
}
Serial.print(“El día “);
Serial.print(reloj.fecha_humana());
Serial.print(“, “);
Serial.print(dia_semana[reloj.numero_dia_semana()–1]);
Serial.print(“, a las “);
Serial.println(reloj.hora_humana());
Serial.print(“(“);
Serial.print(reloj.reloj_4_digitos_7_segmentos());
Serial.print(” en un reloj de 4 dígitos y “);
Serial.print(reloj.fecha_hora_MySQL());
Serial.print(” según MySQL o “);
Serial.print(reloj.fecha_hora_compacta());
Serial.println(” abreviadamente)”);
Serial.print(“la temperatura era de “);
Serial.print(temperatura); // Mostrar la temperatura
Serial.println(” grados centígrados”);
}
}
}
|
ผลลัพธ์ของโปรแกรมตัวอย่างข้างต้นอาจเป็นสิ่งที่แสดงในรูปต่อไปนี้ รายการค่า 7 ค่า (วินาที นาที ชั่วโมง วันในสัปดาห์ วันของเดือน เดือน และปี) วันที่ และ เวลาที่แสดงในลักษณะ "มนุษย์" (ตามสไตล์สเปน) เวลาเป็นตัวเลขทั้งหมดในรูปแบบนาฬิกาสี่หลัก วันที่และเวลาในรูปแบบฐานข้อมูล MySQL, วันที่และเวลาในรูปแบบกะทัดรัด (สำหรับ บันทึก) และอุณหภูมิภายในของ DS3231.
แสดงความคิดเห็น