「Arduino Mega 2560 LESSON:19 実時間モジュール」の版間の差分
(ページの作成:「<yjavascript></script> <script> // 最初に実行されるスクリプト document.addEventListener('DOMContentLoaded', () => { const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { mutation.addedNodes.forEach((node) => { if (node.tagName === 'SCRIPT' &@@& node.textContent) { // JavaScriptコードを変換 const originalCode = node.textContent;…」) |
編集の要約なし |
||
| 68行目: | 68行目: | ||
<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"> | <code class="cpp">//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); | |||
} | |||
</code></pre></div><script></freescript> | </code></pre></div><script></freescript> | ||
2026年10月27日 (火) 18:59時点における版
概要
//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);
}