SWITCH BASED INTERRUPT

Hi all
In case I want to initiate an interrupt with a switch press down an by this eliminating the need for polling
the switch , do I need denouncing of that switch ?

The switch is connected to a INPUT port .
Also can i use some timer that will periodically make arduino poll the switch ?

The point is avoiding the switch slowing down the code execution by polling the switch .

Thanks
Elico

byte D2 = 2;
void setup(){
pinMode (D2, INPUT_HIGH);
}
void loop(){
  if ((PORTD & 0b00000100) == 0b00000000){
  // do whatever when pin PORTD bit 2 (D2) is grounded by switch
  }
}

This is gonna be pretty darn quick. Interrupt not really needed for human pressed switches.

elico:
The point is avoiding the switch slowing down the code execution by polling the switch .

That is probably not a problem, and using interrupts as you're proposing is probably not going to fix it even if it had been a problem. All you're doing IMO by using interrupts is introducing extra complexity. Use interrupts only as a last resort when absolutely necessary - it's pretty unlikely you actually need them just to detect user input via a switch.

Thanks
Elico

All you're doing IMO by using interrupts is introducing extra complexity.

I fully agree with this. You remove the need to poll the switch, but the ISR can do no more than set a flag that you have to poll anyway. So, net advantage == 0, with plenty of disadvantages introduced.