#define LED_PIN PC13
#define KEY_PIN PA0

void dot() {
  digitalWrite(LED_PIN, LOW);
  delay(300);
  digitalWrite(LED_PIN, HIGH);
  delay(300);
}

void dash() {
  digitalWrite(LED_PIN, LOW);
  delay(800);
  digitalWrite(LED_PIN, HIGH);
  delay(300);
}

void morse_U() {
  dot();
  dot();
  dash();
}

void morse_a() {
  dot();
  dash();
}

void morse_f() {
  dot();
  dot();
  dash();
  dot();
}

void morse_g() {
  dash();
  dash();
  dot();
}

void morse_r() {
  dot();
  dash();
  dot();
}

void setup() {
  pinMode(LED_PIN, OUTPUT);
  pinMode(KEY_PIN, INPUT);
  digitalWrite(LED_PIN, LOW);
}

int btnCurrVal;
int btnPrevVal = LOW;
long lastDebounceTime = 0;

void loop() {
  btnCurrVal = digitalRead(KEY_PIN);
  if (btnCurrVal != btnPrevVal) {
      lastDebounceTime = millis();
  //   delay(50);
  //   int btnverifVal = digitalRead(KEY_PIN);
  //   if (btnverifVal == btnCurrVal) {
  //     digitalWrite(LED_PIN, HIGH);
  //     // digitalWrite(LED_PIN, !digitalRead(LED_PIN));
  //   }
  // }
  // else {
  //   digitalWrite(LED_PIN, LOW);
  //   delay(50);
  // }

  if ((millis() - lastDebounceTime) > 50) {
    if (btnCurrVal != btnPrevVal) {
      btnPrevVal = btnCurrVal;
      if (btnPrevVal == HIGH) {
        digitalWrite(LED_PIN, !digitalRead(LED_PIN));
      }
    }
  }

  // digitalWrite(LED_PIN, LOW);
  btnPrevVal = btnCurrVal;


  // morse_U();
  // delay(600);
  // morse_r();
  // delay(600);
  // morse_f();
  // morse_a();
  // morse_g();
  // delay(2000);

  // digitalWrite(LED_PIN, LOW);
  // delay(200);
  // digitalWrite(LED_PIN, HIGH);
  // delay(800);
}
