Using Interrupts on Arduino

I am using an Arduino Mega ADK to learn how to use Interrupts. I tried to run the following program provided as an example at attachInterrupt() - Arduino Reference. I could not get it to work!

I have some questions with regard to this:
a) Is pin 13 serviced by interrupts? I did not think so!
b) Can an ISR be used on both input and output pins or just on the former?
c) When 'pinmode' is used to declare a pin as an OUTPUT pin, without following it with a "digitalWrite" immediately, what is the default state of the pin? I ask this because I thought perhaps the code, as it currently is, was not causing a CHANGE in the pin state?

I appreciate your help!

mosfet2u:
I am using an Arduino Mega ADK to learn how to use Interrupts. I tried to run the following program provided as an example at attachInterrupt() - Arduino Reference. I could not get it to work!

I have some questions with regard to this:
a) Is pin 13 serviced by interrupts? I did not think so!
b) Can an ISR be used on both input and output pins or just on the former?
c) When 'pinmode' is used to declare a pin as an OUTPUT pin, without following it with a "digitalWrite" immediately, what is the default state of the pin? I ask this because I thought perhaps the code, as it currently is, was not causing a CHANGE in the pin state?

a: Pins aren't serviced. Do you mean can pin 13 on a Mega ADK generate an interrupt? If that's your question the answer is yes.

b: Both

c: The reset value is zero.

Thank you 'jboyton' for the clarifications! I have a follow-up:
a) On this page ... docs.cc ... for the Mega ADK, it only seems to list 2, 3, 18-21 as interrupt configurable. Am I misinterpreting the information?
b) Do you have an idea why I cannot get the program I listed earlier to work? Btw, I am using the internal LED connected to pin 13.

Thanks again!

They are leaving out pin change interrupts. They work differently than the so-called external interrupts but will certainly generate an interrupt at a pin. The SoftwareSerial library relies upon them. And there is a PinChangeInt library which provide an interface.

Sorry, I don't see any code.

I apologize ... my mistake ... here it is ...

Example

int pin = 13;
volatile int state = LOW;

void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, CHANGE);
}

void loop()
{
digitalWrite(pin, state);
}

void blink()
{
state = !state;
}

What is triggering the interrupt by producing a change on pin 2 (external interrupt 0 is on Pin 2)?

Thank you "cattle dog". That was my question exactly! Here is some more detail on what bothered me about this program (which, by the way, was an example from an Arduino page) ... attachInterrupt() - Arduino Reference

a) The program uses the built-in LED connected to pin 13 (but as you point out, it is not pin 2, which is the one that relates to external interrupt 0; I was puzzled by this too!).
b) Setting that aside, the change on pin 13 is caused by toggling the 'state' variable. This bothered me some, because whether the state is toggled the first time (by the 'digitalWrite" command in the 'loop' function), would be determined by what the initial state assumed is, when the pin is declared as an OUTPUT pin. That is, what is the default state after this declaration?! If there is no change, the interrupt routine will never be triggered.
c) Subsequently I rigged an external LED to pin 2, modified the program accordingly and ran it again, but it still does not work!

Thanks again for your help!

The example code presumes that there is a changing signal applied to the interrupt pin 2 and it should be more clear about that.

Here is that example code slightly modified to generate a pulse on pin 8. Connect pin 8 to pin 2 with a jumper wire. It will trigger an interrupt which will blink the led on pin 13.

int ledPin = 13;
int signalPin = 8;//jumper pin 8 to pin 2
int interval = 5000;
unsigned long lastChange;

volatile int state = LOW;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(signalPin, OUTPUT);
  attachInterrupt(0, blink, CHANGE);
}

void loop()
{
  //generate interrupt pulse
  if (millis() - lastChange >= interval) {
    digitalWrite(signalPin, !digitalRead(signalPin));//toggle signalPin
    lastChange = millis();
  }
  digitalWrite(ledPin, state);
}

void blink()
{
  state = !state; //toggle ledPin
}

Yes, it works! I added a line of code initializing 'lastChange' to 0, but I guess it is not needed, since the default value is zero upon definition?

Thanks!