#define faz 4
#define buzzer 1
#define led 5
const int buttonPin = 3;
int buttonState;
int lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
int on_off =0;
unsigned long simdikiZaman, eskiZaman = 0;
void setup() {
pinMode(faz, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(led ,OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(faz, LOW);
digitalWrite(led, LOW);
digitalWrite(buzzer, LOW);
}
void loop() {
/////// BUTON DEBOUNCE KODLARI /////////////////
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
if (on_off == 0) {
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
delay(1500);
digitalWrite(buzzer, LOW);
digitalWrite(led, HIGH);
digitalWrite(faz, HIGH);
on_off = 1;
} else if (on_off == 1) {
digitalWrite(buzzer, HIGH);
delay(2000);
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
digitalWrite(faz, LOW);
on_off = 0;
}
}
}
}
///////////////////////////////////////////
}