#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 20, 4);
Servo servo1;
Servo servo2;
Servo servo3;
const int buttonSetTime = 22;
const int buttonSetDown = 23;
const int buttonSetUp = 24;
const int buttonSetAlarm = 25;
const int buttonKuning = 11; // Push button kuning untuk servo 1
const int buttonBiru = 12; // Push button biru untuk servo 2
const int buttonMerah = 13; // Push button merah untuk servo 3
const int ledKuning = 6; // LED kuning
const int ledBiru = 5; // LED biru
const int ledMerah = 4; // LED merah
const int buzzerPin = 7;
bool alarmActive = false;
void setup() {
lcd.init();
lcd.backlight();
pinMode(buttonSetTime, INPUT_PULLUP);
pinMode(buttonSetDown, INPUT_PULLUP);
pinMode(buttonSetUp, INPUT_PULLUP);
pinMode(buttonSetAlarm, INPUT_PULLUP);
pinMode(buttonKuning, INPUT_PULLUP);
pinMode(buttonBiru, INPUT_PULLUP);
pinMode(buttonMerah, INPUT_PULLUP);
pinMode(ledKuning, OUTPUT);
pinMode(ledBiru, OUTPUT);
pinMode(ledMerah, OUTPUT);
pinMode(buzzerPin, OUTPUT);
servo1.attach(8); // PWM pin untuk servo 1
servo2.attach(9); // PWM pin untuk servo 2
servo3.attach(10); // PWM pin untuk servo 3
Wire.begin();
rtc.begin();
if (!rtc.isrunning()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set RTC dengan tanggal dan waktu kompilasi
}
lcd.setCursor(0, 0);
lcd.print("Medicine Reminder");
}
void loop() {
DateTime now = rtc.now();
lcd.setCursor(0, 1);
lcd.print(now.timestamp(DateTime::TIMESTAMP_TIME));
lcd.setCursor(0, 2);
lcd.print(now.timestamp(DateTime::TIMESTAMP_DATE));
if (digitalRead(buttonSetTime) == LOW) {
// Implementasi pengaturan waktu
}
if (digitalRead(buttonSetDown) == LOW) {
// Implementasi penurunan
}
if (digitalRead(buttonSetUp) == LOW) {
// Implementasi peningkatan
}
if (digitalRead(buttonSetAlarm) == LOW) {
// Implementasi pengaturan alarm
alarmActive = !alarmActive;
digitalWrite(ledBiru, alarmActive ? HIGH : LOW);
}
if (digitalRead(buttonKuning) == LOW) {
// Gerakkan servo 1
servo1.write(90); // Contoh posisi servo
digitalWrite(ledKuning, HIGH); // LED kuning menyala
tone(buzzerPin, 1000); // Bunyikan buzzer (frekuensi 1000 Hz)
} else {
servo1.write(0); // Reset posisi servo
digitalWrite(ledKuning, LOW); // Matikan LED kuning
noTone(buzzerPin); // Matikan bunyi buzzer
}
if (digitalRead(buttonBiru) == LOW) {
// Gerakkan servo 2
servo2.write(120); // Contoh posisi servo
digitalWrite(ledBiru, HIGH);
tone(buzzerPin, 1500); // LED biru menyala
} else {
servo2.write(0); // Reset posisi servo
digitalWrite(ledBiru, LOW); // Matikan LED biru
}
if (digitalRead(buttonMerah) == LOW) {
// Gerakkan servo 3
servo3.write(60); // Contoh posisi servo
digitalWrite(ledMerah, HIGH);
tone(buzzerPin, 2000);// LED merah menyala
} else {
servo3.write(0); // Reset posisi servo
digitalWrite(ledMerah, LOW); // Matikan LED merah
}
if (alarmActive && now.second() == 0) {
// Implementasi alarm (misalnya, pada detik ke-0 setiap menit)
tone(buzzerPin, 2000); // Bunyikan buzzer dengan frekuensi 2000 Hz
}
else {
noTone(buzzerPin); // Matikan bunyi buzzer
}
}