]> kolegite.com Git - vmks.git/commitdiff
added an example for external interrupt
authorvl_garistov <vl.garistov@gmail.com>
Sat, 24 Oct 2020 21:58:52 +0000 (21:58 +0000)
committervl_garistov <vl.garistov@gmail.com>
Sat, 24 Oct 2020 21:58:52 +0000 (21:58 +0000)
LED_strip_2/LED_strip_2.ino [new file with mode: 0644]
LED_strip_2/LED_strip_2.png [new file with mode: 0644]

diff --git a/LED_strip_2/LED_strip_2.ino b/LED_strip_2/LED_strip_2.ino
new file mode 100644 (file)
index 0000000..77ba930
--- /dev/null
@@ -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 (file)
index 0000000..2d29e5c
Binary files /dev/null and b/LED_strip_2/LED_strip_2.png differ