#include <TFT_eSPI.h>

#define EXT_RAD 20
#define INT_RAD 15

TFT_eSPI tft = TFT_eSPI();

int ledState1 = LOW, ledState2 = LOW, ledState3 = LOW;
int ledsPosition[3][2] = {{60, 67}, {120, 67}, {180, 67}};
unsigned long ledsColors[3] = {TFT_RED, TFT_GREEN, TFT_BLUE};

void setup() {
  Serial.begin(9600);        // Start serial communication at 9600 baud
  tft.init();
  tft.setRotation(1); // Adjust rotation if needed
  tft.fillScreen(TFT_BLACK);
  tft.drawCircle(120, 67, 20, TFT_RED);

  for (int i = 0; i < 3; ++i)
  {
    tft.drawCircle(ledsPosition[i][0], ledsPosition[i][1], EXT_RAD, ledsColors[i]);
  }
}

void loop() {
  if (Serial.available() > 0) {
    char command = Serial.read();
    switch (command)
    {
      case 'R':
        ledState1 = !ledState1;   // Toggle LED state

        if (ledState1 == HIGH)
          tft.fillCircle(ledsPosition[0][0], ledsPosition[0][1], INT_RAD, ledsColors[0]);
        else
          tft.fillCircle(ledsPosition[0][0], ledsPosition[0][1], INT_RAD, TFT_BLACK);
        break;
      case 'G':
        ledState2 = !ledState2;   // Toggle LED state

        if (ledState2 == HIGH)
          tft.fillCircle(ledsPosition[1][0], ledsPosition[1][1], INT_RAD, ledsColors[1]);
        else
          tft.fillCircle(ledsPosition[1][0], ledsPosition[1][1], INT_RAD, TFT_BLACK);
        break;
      case 'B':
        ledState3 = !ledState3;   // Toggle LED state

        if (ledState3 == HIGH)
          tft.fillCircle(ledsPosition[2][0], ledsPosition[2][1], INT_RAD, ledsColors[2]);
        else
          tft.fillCircle(ledsPosition[2][0], ledsPosition[2][1], INT_RAD, TFT_BLACK);
        break;
    }
  }
}



//int led_pin = 13;
//void setup() {
//  Serial.begin(9600);
//  pinMode(led_pin, OUTPUT);                                // set the digital pin as output:
//}
//void loop() {
//  if(Serial.available())                                   // if there is data comming
//  {
//    String command = Serial.readStringUntil('\n');         // read string until meet newline character
//    if(command == "1")
//    {
//      digitalWrite(led_pin, HIGH);                         // turn on LED
//      //Serial.println("LED is turned ON");                  // send action to Serial Monitor
//      Serial.println("1");
//    }
//    else
//    if(command == "0")
//    {
//      digitalWrite(led_pin, LOW);                          // turn off LED
//      //Serial.println("LED is turned OFF");                 // send action to Serial Monitor
//      Serial.println("0");
//    }
//  }
//}