// Pin Definitions
#define ledOne 11
#define ledTwo 10
#define buttonOne 2
#define buttonTwo 6
#define buttonThree 5
#define buttonFour 4

// Variables
bool ledOne_state = false; // Initial state of LED
int blink_delay = 500; // Initial blinking interval
int brightness = 128; // Initial brightness (PWM)

void setup() {
  pinMode(ledOne, OUTPUT);
  pinMode(ledTwo, OUTPUT);
  pinMode(buttonOne, INPUT_PULLUP);
  pinMode(buttonTwo, INPUT_PULLUP);
  pinMode(buttonThree, INPUT_PULLUP);
  pinMode(buttonFour, INPUT_PULLUP);
}

void loop() {
  // Toggle the top LED
  if (digitalRead(buttonOne) == LOW) {
    ledOne_state = !ledOne_state;
    digitalWrite(ledOne, ledOne_state ? HIGH : LOW);
    delay(100); // Debouncing delay
  }

  // Blink the second top LED
  static unsigned long previousMillis = 0;
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= blink_delay) {
    digitalWrite(ledTwo, !digitalRead(ledTwo));
    previousMillis = currentMillis;
  }

  // Adjust blinking speed
  if (digitalRead(buttonTwo) == LOW) {
    blink_delay -= 50;
    if (blink_delay < 50) blink_delay = 50; // Minimum interval
    delay(100); // Debouncing delay
  }
  if (digitalRead(buttonThree) == LOW) {
    blink_delay += 50;
    if (blink_delay > 1000) blink_delay = 1000; // Maximum interval
    delay(100); // Debouncing delay
  }

  // Adjust brightness with PWM
  if (digitalRead(buttonFour) == LOW) {
    brightness += 10;
    if (brightness > 255) brightness = 255; // Maximum brightness
    analogWrite(ledTwo, brightness);
    delay(100); // Debouncing delay
  }
}