From: vl_garistov Date: Sat, 24 Oct 2020 21:58:52 +0000 (+0000) Subject: added an example for external interrupt X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=3a85f8980d06c93f854f71a3291acb473b94460d;p=vmks.git added an example for external interrupt --- diff --git a/LED_strip_2/LED_strip_2.ino b/LED_strip_2/LED_strip_2.ino new file mode 100644 index 0000000..77ba930 --- /dev/null +++ b/LED_strip_2/LED_strip_2.ino @@ -0,0 +1,45 @@ +#define BTN_PIN 2 +#define LED_PIN 13 + +void button_pressed_ISR(void); +void slow_computation(void); + +volatile uint8_t led_state = 0; + +void setup() +{ + pinMode(BTN_PIN, INPUT_PULLUP); + pinMode(LED_PIN, OUTPUT); + attachInterrupt(digitalPinToInterrupt(BTN_PIN), button_pressed_ISR, FALLING); + + Serial.begin(9600); +} + +void loop() +{ + slow_computation(); + + if (led_state) + Serial.println("LED in on."); + else + Serial.println("LED in off."); +} + +void button_pressed_ISR(void) +{ + if (led_state) + { + led_state = 0; + digitalWrite(LED_PIN, LOW); + } + else + { + led_state = 1; + digitalWrite(LED_PIN, HIGH); + } +} + +void slow_computation(void) +{ + delay(5000); +} \ No newline at end of file diff --git a/LED_strip_2/LED_strip_2.png b/LED_strip_2/LED_strip_2.png new file mode 100644 index 0000000..2d29e5c Binary files /dev/null and b/LED_strip_2/LED_strip_2.png differ