#include <LiquidCrystal_I2C.h> // LCD I2C용 라이브러리
#include <RTClib.h> // 실시간시계 라이브러리
#include <Wire.h> // I2C통신 라이브러리
LiquidCrystal_I2C lcd(0x27,16,2); // 접근주소: 0x3F or 0x27
RTC_DS1307 RTC;
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup() {
Serial.begin(9600); // 시리얼통신 초기화
pinMode(2, OUTPUT);
lcd.init(); // LCD 초기화
lcd.backlight(); // LCD 백라이트 켜기
RTC.begin(); // 실시간시계 시작
Wire.begin();
mpu.initialize();
mpu.setFullScaleGyroRange(MPU6050_GYRO_FS_250);
// RTC.adjust(DateTime(2022,9,30,18,13,40)); // 처음 한번만 적절한 날짜 시간으로 설정, 이후 주석처리
}
void loop() {
digitalWrite(2, HIGH);
int16_t ax, ay, az;
int16_t gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// Mengubah nilai gyro menjadi derajat per detik
float gyroX = (float)gx / 131.0;
float gyroY = (float)gy / 131.0;
float gyroZ = (float)gz / 131.0;
Serial.print("Gyro X: ");
Serial.print(gyroX);
Serial.print(" derajat/s\t");
Serial.print("Gyro Y: ");
Serial.print(gyroY);
Serial.print(" derajat/s\t");
Serial.print("Gyro Z: ");
Serial.print(gyroZ);
Serial.println(" derajat/s");
delay(100);
DateTime now=RTC.now();
lcd.setCursor(0,0); lcd.print("DATE: ");
lcd.print(now.year()); lcd.print("/"); lcd.print(now.month()); lcd.print("/"); lcd.print(now.day());
lcd.setCursor(0,1); lcd.print("TIME: ");
lcd.print(now.hour()); lcd.print(":"); lcd.print(now.minute()); lcd.print(":"); lcd.print(now.second());
delay(1000);
}