Help Can't get Inturrupt to work..

I have a project where I'm trying to get the Arduino to perform a series of tasks when I push a button, part of the functionality is that I want it to stop what it's doing and wait for the input again if I push the button again while it's running through it's tasks.

For the life of me I can't get interrupts to work, it's as if I don't have them set at all.

this is the bare bones code, I have a button on 1 with a pull up resistor to 5V, and an LED on pin 13

when I push the button the first time, the LED lights, up.... if I push it again it just ignores my input and stays lit.

I feel like I must be missing something really simple. Any help would be appreciated.

this is 100% of the code.

int pbIn = 1;
int ledOut = 13;

void setup(){               
  pinMode(pbIn, INPUT);
  pinMode(ledOut, OUTPUT);
  attachInterrupt(pbIn, stateChange, CHANGE);
}

void loop(){
  if (digitalRead(pbIn) == HIGH) {
    digitalWrite(ledOut, HIGH); 
    delay(50000);
  }
}

void stateChange(){
  digitalWrite(ledOut, LOW); 
}

A CHANGE interrupt handler will fire when the switch is pressed, and again when it is released. Is that what you really want?

1) PIN 1 is the serial port, it is not recommended to use this for IO other than serial, however no real problem in your sketch. 2) The IRQ lines are line 2 and 3 and identified as 0 and 1

Connect the switch to pin 2 to run this minimal IRQ example

try this,

int ledOut = 13;

void setup()
{               
  pinMode(2, INPUT);
  pinMode(ledOut, OUTPUT);
  attachInterrupt(0, stateChange, CHANGE);
}

void loop()
{
}

void stateChange()
{
  digitalWrite(ledOut, !digitalRead(ledOut));  // every irq it will change state
}

PaulS:
A CHANGE interrupt handler will fire when the switch is pressed, and again when it is released. Is that what you really want?

not in the final sketch, no, however I wrote this as a simplified sketch to simply get the interrupt functionality figured out and I simply wanted to see ANY signs of life from the interrupt handler, for that “CHANGE” is perfect.

robtillaart:

  1. PIN 1 is the serial port, it is not recommended to use this for IO other than serial, however no real problem in your sketch.
  2. The IRQ lines are line 2 and 3 and identified as 0 and 1

Connect the switch to pin 2 to run this minimal IRQ example

I didn’t realize that IRQ couldn’t only be used on certain lines, I’ll try moving the pin later tonight, Thanks!