Manual
www.nexusrobot.com Robot Kits manual
32
7.
8. #define PIN 15 // the pin we are interested in
9. byte burp=0; // a counter to see how many times the pin has changed
10. byte cmd=0; // a place to put our serial data
11. void setup() {
12. Serial.begin(9600);
13. Serial.print("PinChangeInt test on pin ");
14. Serial.print(PIN);
15. Serial.println();
16. pinMode(PIN, INPUT); //set the pin to input
17. digitalWrite(PIN, HIGH); //use the internal pullup resistor
18. PCintPort::attachInterrupt(PIN, burpcount,RISING); // attach a PinChange Interrupt to our pin on
the rising edge
19. // (RISING, FALLING and CHANGE all work with this library)
20. // and execute the function burpcount when that pin changes
21. }
22. void loop() {
23. cmd=Serial.read();
24. if (cmd=='p')
25. {
26. Serial.print("burpcount:\t");
27. Serial.println(burp, DEC);
28. }
29. cmd=0;
30. }
31. void burpcount()
32. {
33. burp++;
34. }
See: http://arduino.cc/playground/Main/PinChangeIntExample