Pages: [1]   Go Down
Author Topic: attachInterrupt question  (Read 405 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 3
Posts: 277
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using a DS18B20 temperature sensor to display temperature data onto a serial LCD.  I have a simple push button that I use to toggle back and forth between celsius and farenheit.  I am using the attachInterrupt command to read the push button.  My problem is that the pushbutton seems to need some sort of debounce because occassionally it will toggle from celsius to farenheit and back to celsius on one push.  Would the debounce routine go somewhere in the function that is called by the interrupt?  
Logged

Arduino Uno;
Mega328

Canberra, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 31
I always look this excited
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In my first AttachInterrupt attempt I found the same problem. Brushing my two bits of hookup wire together [my 'switch'] produced anything up to 5 interrupts. My not-so-sophisticated debounce routine consisted of ignoring any interrupt within a second of the previous one. My needs were simple so this sufficed.

Code:
//globals.
long lastint = 0; //when last interrupt occurred.
...
void int0_isr()
{
  if(abs(millis() - lastint) < 1000)//less than a sec since last int.
  {
    lastint = millis();
    return;
  }
  Serial.println("int0 called");
  lastint = millis();
...
Logged

Cheers,

PeterV in Canberra

0
Offline Offline
Sr. Member
****
Karma: 3
Posts: 277
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That looks pretty good.  I'm gonna try it.  Thanks!
Logged

Arduino Uno;
Mega328

Pages: [1]   Go Up
Jump to: