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

提供:yonewiki
編集の要約なし
編集の要約なし
タグ: 手動差し戻し
 
(同じ利用者による、間の19版が非表示)
75行目: 75行目:




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




[[|380px||none|PCB図]]
[[ファイル:Mega2560 L16 03 PCB図.png|380px||none|PCB図]]




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




[[|380px||none|3Dプレビュー図]]
[[ファイル:Mega2560 L16 04 3DPreview図.png|380px||none|3DPreview図]]




 コードは以下のようなものです。
 コードは以下のようなものです。
<freescript></script><div class="hljs-wrap"><pre data-label="Arduino Code" class="pre-wrap">
<freescript></script><div class="hljs-wrap"><pre data-label="Arduino Code" class="pre-wrap">
<code class="cpp">//www.elegoo.com
<code class="cpp">//www.elegoo.com

2026年10月28日 (水) 20:03時点における最新版

Arduino Mega 2560に戻る。

概要

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


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


完成図


 PCB図は以下のようなモノ


PCB図


 3DPreview図は以下のようなモノ


3DPreview図


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

//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に戻る。