internal pull up resistor?

ok..so Im a bit stumped.. this code (at home).. compiles just fine

int pin = 13;
int pin2 = 2;
volatile int state = LOW;

void setup(){
  Serial.begin(9600);
  pinMode(pin, OUTPUT);
  pinMode(pin2, INPUT);
  digitalWrite(pin2, HIGH);
  attachInterrupt(0, ISR1, RISING);
}
void loop(){
  if(state == HIGH){
    Serial.println("--EVENT TRIGGERED--");
    //tone(8, 350, 50);
    digitalWrite(pin, state);
    delay(50);
    state = LOW;
    digitalWrite(pin, state);
  }
}
void ISR1(){
  state = HIGH;
}

but this DOES NOT COMPILE for me:

int pin = 13;
int iPin = 2;
volatile int state = LOW;

void setup(){
  Serial.begin(9600);
  pinMode(pin, OUTPUT);
  pinMode(iPin, INPUT);
  digitalWrite(iPin, HIGH);
  attachInterrupt(0, ISR, HIGH);
}
void loop(){
  if(state == HIGH){
    Serial.println("--EVENT TRIGGERED--");
    digitalWrite(pin, state);
    delay(500);
    state = LOW;
  }
}
void ISR(){
  state = HIGH;
}

outside of different names for some variables.. what could be the difference? Somehow that 'program' is corrupt?
(maybe its something Im overlooking?)

anyways- back to the code/questions.. :slight_smile:

so the code in this post (above) works and compiles..

and 'visually' it looks like it works just fine... with pin13 led coming on whenever the clash sensor is hit.. and then pausing briefly before turning off again..

however.. by watching my output in the serial monitor..I see that 1, 2, or even 3 events are actually being triggered by one 'flick'.. (which is probably correct..since the spring probably flops around making contact a few times)

in the end..this event will trigger a sound to play.. for now I had only used an led as a visual feedback display for my code..

I commented out those few lines..and added in a tone() function.. to play a tone every time the sensor is activated..

here I can also tell the tone plays more than once from one 'hit test/event'

I guess Im looking to take this little code to the next level.

questions/thoughts:

1.) I doubt Id want this to be in the MAIN loop.. would I?
Although I havent used them..or read too much about them.. I am thinking a 'timer' would be better?

so it can have a bit of a 'delay/pause' in between the 'timers' going off?

Do using these 'timers' also stop the code/program flow.. much like the disabling of the interrupt 'listener' when an interrupt service routine is called/executed?

Is there are other limitations for these timers a noob should be aware of?