Pemrograman RTC DS3231 dengan Arduino Uno
# belajar03-arduino-ds3231.ino
#include <Wire.h>
#include "RTClib.h"
/*
* Program RTC DS3231 Dengan ardunio uno
* Tgl : 31 oktober 2020
* Koneksi Pin RTC3231 ke PIN Arduiono UNO
* GND -> GND
* VCC -> +5V
* SCL -> A5
* SCA -> A4
* Provide by : aplikasi-hebat Studio
*
*/
//init rtc3231
RTC_DS3231 rtc;
//
char daysOfTheWeek[7][12] = {"Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"};
void setup () {
//init serial komunikasi dengan serial komputer utk tampil di serial monitor
Serial.begin(9600);
rtc.begin();
delay(3000); // wait for console opening
//setting tanggal awal: thn,bulan,tgl,jam,menit,detik
rtc.adjust(DateTime(2020, 10, 31, 15, 22, 0));
}
void loop () {
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(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.println();
delay(1000);
}
No comments:
Post a Comment