我一直在尝试创建一个从 unix 时间戳开始计数的天数计数器。我正在使用 arduino Leonardo、RTC DS 3231 和 7 段串行显示器(通过 microbot)。这是显示链接:串行显示链接
但我无法让显示器打印任何输出。我想我可能搞砸了连接。
我已将 rtc 的 Vcc 和 Gnd 连接到 arduino 的 3.3v 和 gnd,并将 Sda 和 Scl 连接到 arduino 的 Sda 和 Scl。
对于显示器,我将 Vcc 连接到 5V,将 gnd 连接到 gnd,将 Rx 连接到数字输出 5(这是正确的吗?我知道我在这里搞砸了)
这是代码:
#include <Time.h>
#include <TimeLib.h>
#include <SPI.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "RTClib.h"
RTC_DS1307 rtc = RTC_DS1307();
Adafruit_7segment clockDisplay = Adafruit_7segment();
int hours = 0;
int minutes = 0;
int seconds = 0;
unsigned long previousMillis = 0; // will store last millis event time
unsigned long sensorpreviousMillis = 0; // will store last millis event time
unsigned long fiveMinuteInterval = 300000; // interval at which to use event time (milliseconds)
unsigned long postDaysInterval = 7200000 ; //seconds in a day 86400000
#define DISPLAY_ADDRESS 0x70
unsigned long theDateWeGotTogether = 1441843200; //in unixtime
unsigned long days ;
int weeks ;
void setup() {
Serial.begin(115200);
clockDisplay.begin(DISPLAY_ADDRESS);
rtc.begin();
bool setClockTime = !rtc.isrunning();
if (setClockTime) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
// DateTime now = rtc.now();
days = ((now() - theDateWeGotTogether) / 86400); //86400 is the number of seconds in a day
unsigned long currentMillis = millis();
ShowDaysReading();
time_t t = now();
if(currentMillis - sensorpreviousMillis > fiveMinuteInterval)
{
// save the last time you performed event
sensorpreviousMillis = currentMillis;
DateTime Zeit = rtc.now();
}
}
void ShowDaysReading()
{
days = ((now() - theDateWeGotTogether) / 86400); //86400 number of seconds in a day
weeks = ((now() - theDateWeGotTogether) / (86400 * 7) ); //86400 number of seconds in a day
clockDisplay.print(days);
}