Arduino interrupts and debounce.

I built a project based on the Sparkfun weather station - using the code from here http://kesslerarduino.wordpress.com/2012/06/21/sparkfun-weather-station/
Since I added RF24 code to do it wireless on batteries - to make the batteries last longer I implemented sleep via the watchdog.

Kessler’s code used micros() to debounce the reed switch. Since micros() were used the timer interrupt the only thing I could figure to do was once the interrupt woke up the processor keep it awake for a few milliseconds to give it time to complete the debounce. But everything locks up after a little while. (40-100 or so 15 second periods)

the new interrupt routine is

void anemometerClick()
{
  anem_iflag=true;
  long thisTime=micros()-anem_last;
  anem_last=micros();
  if(thisTime>500)
  {
    anem_count++;
    anem_iflag=false;
    if(thisTime<anem_min)
    {
      anem_min=thisTime;
    }
 
  }
}

The sleep code has new delay to keep everything alive until the debounce flag is reset - or timeout

    while( sleep_cycles_remaining ){
      // if we got here via interrupt then keep the timers 
      // running until they debounce
      do_sleep();//SLEEP -  Interrupts continue after here
      int timeout= 10;
      unsigned long now=millis();  // time in milliseconds 
      while (anem_iflag == true && (millis () - now) <= timeout);
      //in case we time out - make sure the flag is reset
      anem_iflag=false;   


     while (rain_iflag == true && (millis () - now <= timeout));
      //in case we time out - make sure the flag is reset
      rain_iflag=false;
    }

What am i missing??? (the full sketch is too big to attach)

the full sketch is too big to attach

The attachment "limit" is about 4MB, IIRC That's an awful lot of source code

My Bad - i was trying to put the code between code tags.
the code is attached

SparkfunWeather.ino (9.4 KB)

Still not able to see the full code above

You could always denounce the switch using hardware. Most of the time a simple rc filter will do the job, although a 555 timer wired up as a one shot is even better. Inverting Schmit triggers also work great but not always the most abundant IC in the toolbox

I would try a more reasonable debounce period like 200milliseconds.

What woould be a good starting point for the r/c filter - 100k and .1uf?

I tend to start off with 10k and .1uf but thats only cos I know it usually works and I have loads of those lying around. The problem with having to a discharge time that is too long is that the pin reading stays in the in-between state (not high and not low) for too long which can give you other issues. Best to experiment ;)