Hello! I want to control my leds using bluetooth. So adruino compare the time app with the rtc time and than, if they are the same, the buzzer is activated. The user can choose what leds to light up at a specific time by sending an input. If the user send "on" , led 13 should light up or "on1" should activate led 10. How can I add another input?. I think a have to change something in the getValue function, but i don't know how... Should i write String led = getValue(input, ':', 2);? Can someone help me?
void loop ()
{
String input = "";
while(bt.available())
{
input += (char)bt.read();
delay(5);
}
now = rtc.now();
showDate();
showDay();
showTime();
String firstHalf = getValue(input, ':', 0); // check first input untill ":"
String secondHalf = getValue(input, ':', 1); // check second input after ":"
// check first 2 digits inputs, then check second 2 digits of input
if (now.hour() == firstHalf.toInt() && now.minute() == secondHalf.toInt())
{
/* if(input=="on")
{
digitalWrite( 13, HIGH);
}
else
{
digitalWrite( 13, LOW);
}
*/
start(); //start buzzer
}
}
// logic to seperate strings
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}