#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;
char startChar = '*';
char endChar = '#';
char slots[4][6] = {"", "", "", ""}; // 4 slots as 2D array
int leds[4] = {12, 11, 10, 9}; // LED pins
int buzzer = 8;
String incomingData = "";
int commas[5]; // to store comma positions
void setup()
{
Serial.begin(9600);
Serial.println("HELLO");
rtc.begin();
for (int i = 0; i < 4; i++)
{
pinMode(leds[i], OUTPUT);
}
pinMode(buzzer, OUTPUT);
}
void loop()
{
DateTime now = rtc.now();
char currenttime[6];
sprintf(currenttime, "%02d:%02d", now.hour(), now.minute());
Serial.println(currenttime);
if (Serial.available() > 0)
{
incomingData = Serial.readStringUntil(endChar);
if (incomingData[0] == startChar)
{
// Directly use commas[i]
for (int i = 0; i < 5; i++)
{
commas[i] = incomingData.indexOf(',', (i == 0) ? 1 : commas[i - 1] + 1);
}
// Extract and store slot values
for (int i = 0; i < 4; i++)
{
incomingData.substring(commas[i] + 1, commas[i + 1]).toCharArray(slots[i], 6);
}
Serial.println("Separated Values:");
for (int i = 0; i < 4; i++)
{
Serial.print("SLOT ");
Serial.print(i + 1);
Serial.print(": ");
Serial.println(slots[i]);
}
}
}
// Check each slot
for (int i = 0; i < 4; i++)
{
if (strcmp(slots[i], currenttime) == 0)
{
digitalWrite(leds[i], HIGH);
digitalWrite(buzzer, HIGH);
delay(1500);
digitalWrite(leds[i], LOW);
digitalWrite(buzzer, LOW);
}
}
delay(200);
}