我做了一个项目来记录温度和时间,但是在打印记录时,时间并没有像 24 小时格式那样以正确的方式显示。
我得到的是:
2015 年 8 月 4 日 15:57:09 24.9
2015 年 8 月 4 日 15:57:39 25.39
2015 年 8 月 4 日 15:58:09 25.39
2015 年 8 月 4 日 15:58:39 23.44
2015 年 8 月 4 日 15:59:09 24.9
2015 年 8 月 4 日 15:59:39 25.39
2015 年 8 月 4 日 10:00:09 24.9
2015 年 8 月 4 日 10:00:39 25.39
2015 年 8 月 4 日 10:01:09 25.39
2015 年 8 月 4 日 10:01:39 25.39
2015 年 8 月 4 日 10:02:09 25.39
2015 年 8 月 4 日 10:02:39 25.39
但我希望它是:
2015 年 8 月 4 日 15:59:09 24.9
2015 年 8 月 4 日 15:59:39 25.39
2015 年 8 月 4 日 16:00:09 24.9
2015 年 8 月 4 日 16:00:39 25.39
是因为十六进制数和十进制数的问题吗?
这是arduino uno的代码
#include <DS3231.h>
#include <Wire.h>
#include<SPI.h>
const int temperature = A0;
int refresh = 30000;
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
float atm_temp;
byte year, month, date, DoW, hour, minute, second;
void setup()
{
Wire.begin(); // Start the I2C interface
pinMode(temperature,INPUT); // Pinsetup for temperature sensor
//settime(); // Set time in RTC {uploaded at beginning only once}
Serial.begin(115200); // Start the serial interface
Clock.setClockMode(false); // false for 24 hr and true for 12 hr
}
void loop()
{
timedisp();
tempdisp();
delay(refresh);
}
void tempdisp()
{
atm_temp = ((analogRead(temperature)/10240.0)*5000);
Serial.print(",");
Serial.println(atm_temp);
}
void timedisp()
{
Clock.getTime(year, month, date, DoW, hour, minute, second);
Serial.print(month, DEC);
Serial.print("/");
Serial.print(date, DEC);
Serial.print("/");
Serial.print("20");
Serial.print(year, DEC);
Serial.print(",");
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.print(second, DEC);
}
void settime()
{
Clock.setSecond(50);//Set the second
Clock.setMinute(16);//Set the minute
Clock.setHour(5); //Set the hour
Clock.setDoW(3); //Set the day of the week
Clock.setDate(4); //Set the date of the month
Clock.setMonth(8); //Set the month of the year
Clock.setYear(15); //Set the year (Last two digits of the year)
}