100-500ms pulse for external Interrupt

Hi guys,

I am right now trying to get a piezoelectric button to work on pin 2 as an interrupt.

first this is my code:


void funcBut1();

volatile bool but1_int;
bool but1;

void setup() {
attachInterrupt(0, funcBut1, RISING); //0 = interrupt on pin 2
pinMode(LED_BUILTIN, OUTPUT);
pinMode(A0, INPUT);
but1_int = false;
but1 = false;

delay(100);
}

void loop() {

if(but1_int || digitalRead(A0) == HIGH)
{
but1 = true;
but1_int = false;
digitalWrite(LED_BUILTIN, HIGH);

delay(1000);
}
else {
but1 = false;
}

digitalWrite(LED_BUILTIN, LOW);
}

void funcBut1(){
but1_int = true;
}


As you might see, I also try it with the classic approach as a simple input and in this case it works.

The trouble now is whatever mode for the interrupt I choose, I don't get it working with the button.
Surprisingly it works when i unplug the jumper wire or plug it to ground.
Due to this might it be possible that the impulse (~ 100-500ms) is too fast or to slow?
Or might there be something else what could cause troubles?

Thanks already in advance for every helpful though/answer. :slight_smile:

Have you a pull down resistor ( say 10K) on pin 2 ? This would be appropriate for a "RISING" edge.

6v6gt:
Have you a pull down resistor ( say 10K) on pin 2 ? This would be appropriate for a "RISING" edge.

Yes, I alternate it between pin A0 and pin 2 when testing (the unused pin gets connected to ground).
So they both are connected to the same 10K pull down resistor when I try one the different methods.

What happens when you make a momentary connection between pin D2 and Vcc (+5v or +3.3v) with A0 pulled low ? Does the LED function for 1 second ?

first i was actually using an Olimexino-328 (should have the same characteristics as an Arduino Duemilanove).

Now i tried the same code and setup on an UNO and it works.
Therefore i have now started a topic in their forum.

6v6gt:
What happens when you make a momentary connection between pin D2 and Vcc (+5v or +3.3v) with A0 pulled low ? Does the LED function for 1 second ?

it already does when unplugging it from low/ground (on both boards).
so it seems like it should basically work easily if it gets triggered already with no current flowing? :confused: