1

UNIXタイムスタンプからカウントを開始する日数カウンターを作成しようとしています。私は arduino Leonardo、RTC DS 3231、および 7 セグメント シリアル ディスプレイ (マイクロボットによる) を使用しています。表示リンクは次のとおりです: Serial Display Link

しかし、ディスプレイにny出力を印刷させることはできません。接続を間違えた可能性があると思います。

Vcc と Gnd を rtc から arduino の 3.3v と gnd に接続し、Sda と Scl を arduino の Sda と Scl に接続しました。

ディスプレイでは、Vcc を 5V に、GND を GND に、Rx をデジタル出力 5 に接続しました (これは正しいですか? ここで sth を台無しにしてしまったことはわかっています)。

コードは次のとおりです。

#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); 
}
4

0 に答える 0