From: Vladimir Garistov Date: Sun, 6 Nov 2022 17:17:10 +0000 (+0200) Subject: Added pin chane interrupt example X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=b4b1545ace148dc55bbd8d1a9cca79cc711aed96;p=vmks.git Added pin chane interrupt example --- diff --git a/Examples/pin_change_demo/pin_change_demo.ino b/Examples/pin_change_demo/pin_change_demo.ino new file mode 100644 index 0000000..db5f18a --- /dev/null +++ b/Examples/pin_change_demo/pin_change_demo.ino @@ -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; +}