Calc 24 hrs rainfall

Hi,
Using a tipping bucket rain sensor connected to an interrupt pin, then calculating rainfall every 10 seconds. My question is how do I calculate the last 24 hours of rainfall?
Maybe my thinking is off on this, but isn't this how you see it on the weather? It rained 3 inches in the last 24 hours...

void countRainGauge() {
   numTipsRain++;
}
void calcRainFall() {
 //Each interrupt represents
//.011 inches of rain, according to the docs.
 numTipsRain = (numTipsRain*.011);
 rain = rain + numTipsRain;
if (millis()>=86400000)//24 hrs
{
   // calculate last 24 hours worth of rain
}
 numTipsRain = 0;        // Reset counter
}

Thanks.

Why do you need an interrupt?
Are you waking the processor with an external interrupt?

numTipsRain = (numTipsRain*.011);

And the next time you increment it in the ISR?

Yes, using an external intterupt to add up a total number.
Then every 10 seconds I calculate the rainfall and reset the counter to zero.

 numTipsRain = (numTipsRain*.011);
void countRainGauge() {
   numTipsRain++;
}

Isn't that going to screw up your arithmetic?

Why are you using an interrupt?

Here is the entire code I am working from. I did not write this nor have I tested it yet.
I am only trying to add the rain sensor and calculations based on this code.
The code uses an external interrupt for the anemometer as well and suggests using it for the rain gauge. If there is a better way to do this let me know.

/* Arduino sketch for Weather device from Sparkfun.
Uses only the wind direction vane and the anemometer (not the rain gauge).

Although the inclination for a weather logger is to run it for
a long time, due to the way Wiring.c implements the millis() function,
this should be restarted, oh, monthly. The millis() functions overflows
after about 49 days. We could allow for that here, and handle the
wraparound, but you've got bigger problems anyway with the delay()
function at an overflow, so it's best to "reboot".

=========================================================
ANEMOMETER
=========================================================
This is connected to Arduino ground on one side, and pin 2 (for the
attachInterrupt(0, ...) on the other.
Pin 2 is pulled up, and the reed switch on the anemometer will send
that to ground once per revolution, which will trigger the interrupt.
We count the number of revolutions in 5 seconds, and divide by 5.
One Hz (rev/sec) = 1.492 mph.

=========================================================
WIND DIRECTION VANE
=========================================================
We use a classic voltage divider to measure the resistance in
the weather vane, which varies by direction.
Using a 10K resistor, our ADC reading will be:
   1023 * (R/(10000+R))
where R is the unknown resistance from the vane. We'll scale
the 1023 down to a 255 range, to match the datasheet docs.

                  +5V
                   |
                   <
                   >     10K
                   <   Resistor
                   <
                   >
                   |
 Analog Pin 5------|
                   |
                   -----------| To weather vane
                              | (mystery resistance)
                   -----------|
                   |
                   |
                 -----
                  ---
                   -
The ADC values we get for each direction (based on a 255 max)
follow, assuming that pointing away from the assembly center
is sector zero. The sector number is just which 45-degree sector
it is, clockwise from the "away" direction. The direction
shown is assuming that "away" is West. Depending how
you orient the system, you'll have to adjust the directions.

Sector   Reading  Direction
  0        18        W
  1        33        NW
  2        57        N
  7        97        SW
  3       139        NE
  6       183        S
  5       208        SE
  4       232        E
The values in the ADC table below list the midpoints between
these, so our reading can vary a bit. We'll pick the first value
that's >= our reading.
=========================================================
RAIN GAUGE
=========================================================
Not implemented here. Hey. I live in Seattle. It's ALWAYS raining. Who
cares how much?
Okay, it would probably be done the same way as the anemometer, and use
attachInterrupt(1, ...) on pin 3. Each interrupt represents
.011 inches of rain, according to the docs.

*********************************************************************/
int rain=0;
#define uint  unsigned int
#define ulong unsigned long

#define PIN_ANEMOMETER  2     // Digital 2
#define PIN_RAINGAUGE  3    // Digital 3
#define PIN_VANE        5     // Analog 5

// How often we want to calculate wind speed or direction
#define MSECS_CALC_WIND_SPEED 5000
#define MSECS_CALC_WIND_DIR   5000
#define MSECS_CALC_RAIN 10000

volatile int numRevsAnemometer = 0; // Incremented in the interrupt
volatile int numTipsRain = 0; // Incremented in the interrupt
ulong nextCalcSpeed;                // When we next calc the wind speed
ulong nextCalcDir;                  // When we next calc the direction
ulong time;                         // Millis() at each start of loop().
int prevRain = 0;
int currRain = 0;

// ADC readings:
#define NUMDIRS 8
ulong   adc[NUMDIRS] = {26, 45, 77, 118, 161, 196, 220, 256};

// These directions match 1-for-1 with the values in adc, but
// will have to be adjusted as noted above. Modify 'dirOffset'
// to which direction is 'away' (it's West here).
char *strVals[NUMDIRS] = {"W","NW","N","SW","NE","S","SE","E"};
byte dirOffset=0;


//=======================================================
// Initialize
//=======================================================
void setup() {
   Serial.begin(9600);
   pinMode(PIN_ANEMOMETER, INPUT);
   digitalWrite(PIN_ANEMOMETER, HIGH);
   attachInterrupt(0, countAnemometer, FALLING);
   attachInterrupt(1, countRainGauge, RISING);
   nextCalcSpeed = millis() + MSECS_CALC_WIND_SPEED;
   nextCalcDir   = millis() + MSECS_CALC_WIND_DIR;
   nextCalcRain   = millis() + MSECS_CALC_RAIN;
}

//=======================================================
// Main loop.
//=======================================================
void loop() {
   time = millis();

   if (time >= nextCalcSpeed) {
      calcWindSpeed();
      nextCalcSpeed = time + MSECS_CALC_WIND_SPEED;
   }
   if (time >= nextCalcDir) {
      calcWindDir();
      nextCalcDir = time + MSECS_CALC_WIND_DIR;
   }
   if (time >= nextCalcRain) {
      calcRainFall();
      nextCalcRain = time + MSECS_CALC_RAIN;
   }
}

//=======================================================
// Interrupt handler for anemometer. Called each time the reed
// switch triggers (one revolution).
//=======================================================
void countAnemometer() {
   numRevsAnemometer++;
}

//=======================================================
// Interrupt handler for rain gauge. Called each time the reed
// switch triggers (.11 inches).  Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). 
//=======================================================
void countRainGauge() {
   numTipsRain++;
}
//=======================================================
// Find vane direction.
//=======================================================
void calcWindDir() {
   int val;
   byte x, reading;

   val = analogRead(PIN_VANE);
   val >>=2;                        // Shift to 255 range
   reading = val;

   // Look the reading up in directions table. Find the first value
   // that's >= to what we got.
   for (x=0; x<NUMDIRS; x++) {
      if (adc[x] >= reading)
         break;
   }
   //Serial.println(reading, DEC);
   x = (x + dirOffset) % 8;   // Adjust for orientation
   Serial.print("  Dir: ");
   Serial.println(strVals[x]);
}


//=======================================================
// Calculate the wind speed, and display it (or log it, whatever).
// 1 rev/sec = 1.492 mph
//=======================================================
void calcWindSpeed() {
   int x, iSpeed;
   // This will produce mph * 10
   // (didn't calc right when done as one statement)
   long speed = 14920;
   speed *= numRevsAnemometer;
   speed /= MSECS_CALC_WIND_SPEED;
   iSpeed = speed;         // Need this for formatting below

   Serial.print("Wind speed: ");
   x = iSpeed / 10;
   Serial.print(x);
   Serial.print('.');
   x = iSpeed % 10;
   Serial.print(x);

   numRevsAnemometer = 0;        // Reset counter
}
void calcRainFall() {
 //Each interrupt represents
//.011 inches of rain, according to the docs.
// 24 hrs millis =  86400000
 rain = rain + (numTipsRain*.011);
if (millis()>=86400000)//24 hrs
{
   // calculate last 24 hours worth of rain
}

 numTipsRain = 0;        // Reset counter
}

Use an interrupt if you're happy with your arithmetic being screwed arbitrarily every time one comes in.

Look at what you're doing and remember that an interrupt can come at any time, even in themidle of your calculation.

need to diffentiate between the volume of rain in inches and the counter. You can't use one var for both .

volatile unsigned long numTipsRain = 0;  // volatile as it is used in an IRQ
float rainToday = 0;

...
void countRainGauge() 
{
   numTipsRain++;
}


void calcRainFall()    // note the other name
{
  //Each tip represents .011 inches of rain, according to the docs.
  rainToday = numTipsRain * 0.011 ;

  if (millis() >= 24 * 60 * 60 * 1000L) // reset after first 24 hrs
  {
    numTipsRain = 0;
  }
}

Yes, i do need different variables. Since the amount of rain is constantly changing, would something like the following work?

void countRainGauge() {
   numTipsRain++;
}

void calcRainFall() {
 //Each interrupt represents.011 inches of rain, according to the docs.

rain = rain +(numTipsRain*.011);
numTipsRain = 0;

if (millis()>= currentMillis + hourTimer) // calc 1 hour of rain and keep in  array hour[23].  
{
 currentMillis= millis();
 y=y++;
 if (y>23)
 {
  y=0;
 }
 hour[y] = rain;
 rain=0;
}

for (int z = 0; z <  23; z++) // add up last  24 hours of rain
{
dailyRain = dailyRain +hour[z];
}

 Serial.print("Last 24 hrs of rain = ");
 Serial.print(dailyRain);
}

Where/when is calcRainFall() called? Is numTipsRain volatile?

If calcRainFall() is called only once per hour, then the time stuff in calcRainFall() is not necessary. If it is called more often, then the rain calculation and numTipsRain reset should occur only when the hour is up.

if (millis()>= currentMillis + hourTimer) // calc 1 hour of rain and keep in  array hour[23].

Adding to time values is not a good idea.

if(millis() - currentMillis >= hourTimer)

achieves the same result, but is safe.

 y=y++;

y++ is equivalent to y=y+1, so this statement is equivalent to y=y=y+1. Is that what you meant?

Where does dailyRain get reset? Looks to me like every time an hour is up, the dailyRain value is incremented, if any rain fell in the last 24 hours. It never gets smaller.

Thanks for the input PaulS. Currently calcRainFall() is called every 10 seconds from the main loop and numTipsRain is volatile.
However, I could change the timing and just call it calcRainFall() every hour. For now I have only added your suggestions.

void calcRainFall() {
 //Each interrupt represents.011 inches of rain, according to the docs.

rain = rain +(numTipsRain*.011);
numTipsRain = 0;

if (millis()- currentMillis >= hourTimer) // calc 1 hour of rain and keep in  array hour[23].  
{
 currentMillis= millis();
 y++;
 if (y>23)
 {
  y=0;
 }
 hour[y] = rain;
 rain=0;
}

for (int z = 0; z <  23; z++) // add up last  24 hours of rain
{
dailyRain = dailyRain +hour[z];
}

 Serial.print("Last 24 hrs of rain = ");
 Serial.print(dailyRain);
 dailyRain = 0;
}