const byte ledPin = 4;
const byte buttonPin = 2;
volatile int parlaklik = 0;
const int kapanmaSure = 1000;
volatile int basilanSure = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(buttonPin), led_kesme, FALLING);
}
void loop() {
analogWrite(ledPin,map(parlaklik%6,0,5,0,255));
}
void led_kesme() {
parlaklik++;
while(!digitalRead(buttonPin)){
basilanSure++;
delay(1);
if(basilanSure >= kapanmaSure){
parlaklik = 0;
analogWrite(ledPin,0);
}
}
basilanSure = 0;
}