Created
December 14, 2021 18:17
-
-
Save woodif/becef34629ad2d4b3b9c45b64839bfe6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* www.arduinona.com | |
* ตัวอย่างการเซ็ตค่าเวลา ให้ DS3231 | |
* ใช้คู่กับ Library DS3231 จาก https://github.com/PilleStat/PilleStat/tree/master/arduino%20code/libraries/DS3231 | |
* วิธีการต่อ | |
* Arduino UNO -> DS3231 | |
* 5V -> VCC | |
* GND -> GND | |
* SDA -> A4 | |
* SCL -> A5 | |
*/ | |
#include <Wire.h> | |
#include "DS3231.h" | |
RTClib RTC; | |
void setup() { | |
/** | |
* เริ่มการสื่อสารกับ Serial monitor | |
*/ | |
Serial.begin(115200); | |
/** | |
* เริ่มการสื่อสารแบบ I2C | |
*/ | |
Wire.begin(); | |
} | |
void loop () { | |
/** | |
* หน่วงเวลาดึงทุกๆ 1 วินาที | |
*/ | |
delay(1000); | |
/** | |
* ดึงเวลาจากโมดูล RTC ด้วยคำสั่ง RTC.now() เก็บไว้ใน object ชือว่า now | |
* ซึ่งสามารถเรียกดึง วันเดือนปีชั่วโมงนาทีวินาที ได้ผ่านฟังก์ชันตัวอย่างด้านล่าง | |
*/ | |
DateTime now = RTC.now(); | |
Serial.print(now.year(), DEC); | |
Serial.print('/'); | |
Serial.print(now.month(), DEC); | |
Serial.print('/'); | |
Serial.print(now.day(), DEC); | |
Serial.print(' '); | |
Serial.print(now.hour(), DEC); | |
Serial.print(':'); | |
Serial.print(now.minute(), DEC); | |
Serial.print(':'); | |
Serial.print(now.second(), DEC); | |
Serial.println(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment