SHARE
TWEET

arduino - pin change interrupts (analog pins)

a guest Dec 4th, 2014 1,135 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/interrupt.h>
  2.  
  3. #define sbi(sfr, bit) ((sfr) |= (1 << (bit)))
  4. #define cbi(sfr, bit) ((sfr) &= ~(1 << (bit)))
  5.  
  6. /* Pin to interrupt map:
  7.  * D0-D7 = PCINT 16-23 = PCIR2 = PD = PCIE2 = pcmsk2
  8.  * D8-D13 = PCINT 0-5 = PCIR0 = PB = PCIE0 = pcmsk0
  9.  * A0-A5 (D14-D19) = PCINT 8-13 = PCIR1 = PC = PCIE1 = pcmsk1
  10.  */
  11.  
  12. volatile int state;
  13.  
  14. void setup()
  15. {
  16.   Serial.begin(9600);
  17.  
  18.   sbi(PCICR, PCIE1);  
  19.   sbi(PCMSK1, PCINT8);
  20.   sbi(PCMSK1, PCINT9);
  21. }
  22.  
  23. void loop()
  24. {
  25.   if (state == 1) {
  26.     Serial.println("ISR was triggered");
  27.     state = 0;
  28.   }
  29. }
  30.  
  31. ISR(PCINT1_vect)
  32. {
  33.   state = 1;
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top