Interrupt problems

Hi there. I'm currently working on the code for a project, but when I tested it it didn't work. I eventually narrowed it down to the interrupt part of the code, I wrote a small test program for the interrupt, which didn't work, then I tried the interrupt example from the arduino website which didn't work either, so it must be the circuit not the code. Circuit: pin 2 connected to bottom left of tactile switch(gap on breadboard running horizontally), top left of switch connected to 10k resistor, connected to 5v. Top right of switch connected to ground. Using this example code:

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;
}

Thanks in advance :)

Ok, I didn’t follow the horizontal / top-left stuff too well without a pic, but you might like to double check you have the switch oriented correctly. It might work if you turn it 90 degrees. The attached pic shows how those 4-legged things are typically made: see the ppart of the pic that shows the internal connections.

If you have an ohm- meter it would be a good idea to verify how yours works…

pushbutton.jpg

Wire up like this, add indicated line:

CrossRoads: Wire up like this, add indicated line:

@CR.... And change the interrupt to FALLING? That seems to go with the pullup / active low idea?

You have no debouncing, you always need debouncing with mechanical switches.