const int buttonPin = 32; // the pin that the button is connected to
const int ledPin = 4; // the pin that the LED is connected to
const int freq = 5000;
const int resol = 8;
const int ledCh = 0;
int buttonState = 0; // variable for storing the button state
int ledState = LOW; // variable for storing the LED state
int counter = 0;
void IRAM_ATTR Ext_INT1_ISR() {
counter++;
if (counter > 2) {
counter = 0;
}
}
void setup() {
ledcSetup(ledCh, freq, resol);
ledcAttachPin(ledPin, ledCh);
pinMode(buttonPin, INPUT); // set the button pin as input with pullup resistor
pinMode(ledPin, OUTPUT); // set the LED pin as output
digitalWrite(ledPin, HIGH);
attachInterrupt(buttonPin,Ext_INT1_ISR,RISING);
Serial.begin(9600); // initialize the LED state
}
void loop() {
buttonState = digitalRead(buttonPin); // read the button state
if (buttonState == HIGH) {
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle+=10){ // changing the LED brightness with PWM
ledcWrite(ledCh, dutyCycle);
delay(500); // debounce delay to prevent false positives
}
}
}