const int buttonPin = 2; // Пин кнопки
const int buzzerPin = 9; // Пин зуммера
bool lastButtonState = LOW;
unsigned long pressStartTime = 0;
bool isPressing = false;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
bool buttonState = digitalRead(buttonPin);
if (buttonState == LOW && !isPressing) {
pressStartTime = millis();
isPressing = true;
}
if (buttonState == HIGH && isPressing) {
unsigned long pressDuration = millis() - pressStartTime;
isPressing = false;
if (pressDuration < 400) {
// Короткое нажатие - точка
playMorse(1);
} else {
// Длинное нажатие - тире
playMorse(3);
}
}
}
void playMorse(int duration) {
digitalWrite(buzzerPin, HIGH);
delay(200 * duration);
digitalWrite(buzzerPin, LOW);
delay(200);
}