//created by Davood Hakemi with ❤
//arduino toggle led state with interrupt cause by key
#define LED_PIN 13
#define KEY_IT_Pin 2
//define state value as volatile byte
volatile uint8_t state = LOW;
void setup() {
//initial pins
pinMode(LED_PIN, OUTPUT);
pinMode(KEY_IT_Pin, INPUT_PULLUP);
//initial interrupt key
attachInterrupt(digitalPinToInterrupt(KEY_IT_Pin), key_pressed, FALLING);
}
void loop() {
digitalWrite(LED_PIN, state);
}
void key_pressed() {
state = !state;
}