Go Down

Topic: attachInterrupt question (Read 497 times) previous topic - next topic

jerseyguy1996

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?  
Arduino Uno;
Mega328

verstapp

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: [Select]

//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();
...
Cheers,

PeterV in Canberra

jerseyguy1996

That looks pretty good.  I'm gonna try it.  Thanks!
Arduino Uno;
Mega328

Go Up