「Arduino Mega 2560 LESSON:19 実時間モジュール」の版間の差分

提供:yonewiki
編集の要約なし
タグ: 差し戻し済み
編集の要約なし
タグ: 手動差し戻し
66行目: 66行目:


== '''概要''' ==
== '''概要''' ==
 DS1307 実時間モジュールを接続するレッスンです。再発しない。
 DS1307 実時間モジュールを接続するレッスンです。





2026年10月28日 (水) 00:21時点における版

Arduino Mega 2560に戻る。

概要

 DS1307 実時間モジュールを接続するレッスンです。


 完成図は以下のとおりです。


完成図


 PCB図は以下のようなものです。


[[|380px||none|PCB図]]


 3Dプレビュー図は以下のようなものです。


[[|380px||none|3Dプレビュー図]]


 コードは以下のようなものです。

//www.elegoo.com
//2018.10.24
#include <Wire.h>
#include <DS3231.h>

DS3231 clock;
RTCDateTime dt;

void setup()
{
  Serial.begin(9600);

  Serial.println("Initialize RTC module");
  // Initialize DS3231
  clock.begin();

  
  // Manual (YYYY, MM, DD, HH, II, SS
  // clock.setDateTime(2016, 12, 9, 11, 46, 00);
  
  // Send sketch compiling time to Arduino
clock.setDateTime(__DATE__, __TIME__);

// 現在設定された時刻を取得
RTCDateTime dt = clock.getDateTime();

// UNIX時刻に変換して6秒加算
uint32_t timestamp = dt.unixtime + 5;

// 補正した時刻をRTCに設定
clock.setDateTime(timestamp);   
  /*
  Tips:This command will be executed every time when Arduino restarts. 
       Comment this line out to store the memory of DS3231 module
  */
}

void loop()
{
  dt = clock.getDateTime();

  // For leading zero look to DS3231_dateformat example

  Serial.print("Raw data: ");
  Serial.print(dt.year);   Serial.print("-");
  Serial.print(dt.month);  Serial.print("-");
  Serial.print(dt.day);    Serial.print(" ");
  Serial.print(dt.hour);   Serial.print(":");
  Serial.print(dt.minute); Serial.print(":");
  Serial.print(dt.second); Serial.println("");

  delay(1000);
}

 

Arduino Mega 2560に戻る。