与Arduino Leonardo和RTC 3231一起建立一个天数柜台

时间:2018-02-11 23:17:20

标签: arduino-uno arduino-ide real-time-clock

我一直在尝试创建一个从unix时间戳开始计数的计数器。我使用的是arduino Leonardo,RTC DS 3231和7段串行显示器(微博)。这是显示链接:Serial Display Link

但我无法让显示器打印出ny输出。我想我可能搞砸了连接。

我已经将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); 
}

0 个答案:

没有答案