const int buttonPin = 2; // Pin for the button
const int buzzerPin = 8; // Pin for the buzzer
int pressCount = 0;
bool lastButtonState = HIGH;
void setup() {
// Use internal pull-up resistor (no external resistor needed)
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
bool currentButtonState = digitalRead(buttonPin);
// Check for button press (transition from HIGH to LOW)
if (lastButtonState == HIGH && currentButtonState == LOW) {
pressCount++;
delay(50); // Debounce delay to prevent false triggers
if (pressCount == 1) {
tone(buzzerPin, 1000, 200); // Short signal
}
else if (pressCount == 2) {
tone(buzzerPin, 2000, 800); // Long signal
}
else if (pressCount == 3) {
tone(buzzerPin, 1500, 100); // Double signal
delay(150);
tone(buzzerPin, 1800, 100);
}
else if (pressCount >= 4) {
pressCount = 1;
tone(buzzerPin, 1000, 200);
}
}
lastButtonState = currentButtonState;
}