char msg[80];  // array to store incoming characters
int idx = 0;   // index into array
int ledPins[] = {15, 2, 4, 5;
int numLeds = 4;
int i = 0;

void setup() {
  // array of GPIO pins
  Serial.begin(115200);
  Serial.println("Program start ");


    for (i=0; i < numLeds; i++) {
    pinMode(ledPins[i], OUTPUT);
    }

 

  // Initialize each GPIO pin as an output and turn on the LED
  for (i = 3; i >= 0; i--) {
    digitalWrite(ledPins[i], LOW);
    delay(500);
  }

}

void loop() {
  // No code needed in the loop for this example
  // Check if data is available to read
  if (Serial.available() > 0) {
    char receivedChar = Serial.rea();

    // If received character is a newline, print the message and reset the index
    if (receivedChar == '\n') {
      msg[idx] = '\0';  // Null-terminate the C-string
      Serial.print("Received message: );
      Serial.println(msg);


      //  turn off the LEDs
      for (i = 0; i < numLeds; i++) {
          digitalWrite(ledPins[i], LOW);
          delay(500);
          }
      if (strstr(msg, "cola") != NULL) {
           digitalWrite(ledPins[2], HIGH);
      }
      
      if (strstr(msg, "sprite") != NULL) {
           digitalWrite(ledPins[0], HIGH);
      }

      if (strstr(msg, "orange") != NULL) {
           digitalWrite(ledPins[1], HIGH);
      }

     



      idx = 0;  // Reset index to start storing at the beginning of msg
    } else if (idx < sizeof(msg) - 1) {  // Ensure we don't go past the end of the array
      // Add the received character to the msg array
      msg[idx] = receivedChar;
      idx++;
    }
  }

}