]> kolegite.com Git - vmks.git/commitdiff
Added pin chane interrupt example
authorVladimir Garistov <vl.garistov@gmail.com>
Sun, 6 Nov 2022 17:17:10 +0000 (19:17 +0200)
committerVladimir Garistov <vl.garistov@gmail.com>
Sun, 6 Nov 2022 17:17:10 +0000 (19:17 +0200)
Examples/pin_change_demo/pin_change_demo.ino [new file with mode: 0644]

diff --git a/Examples/pin_change_demo/pin_change_demo.ino b/Examples/pin_change_demo/pin_change_demo.ino
new file mode 100644 (file)
index 0000000..db5f18a
--- /dev/null
@@ -0,0 +1,27 @@
+volatile bool change_detected = false;
+
+void setup()
+{
+  // put your setup code here, to run once:
+  DDRC &= ~((1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3));
+  PORTC |= (1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3);
+  PCMSK1 |= (1 << PCINT8) | (1 << PCINT9) | (1 << PCINT10) | (1 << PCINT11);
+  PCICR |= (1 << PCIE1);
+  Serial.begin(38400, SERIAL_8E2);
+}
+
+void loop()
+{
+  if (change_detected)
+  {
+    delay(100);
+    Serial.print("Switch changed: ");
+    Serial.println(PINC & ((1 << PINC0) | (1 << PINC1) | (1 << PINC2) | (1 << PINC3)), BIN);
+    change_detected = false;
+  }
+}
+
+ISR(PCINT1_vect)
+{
+  change_detected = true;
+}