Unsigned Long Addition over flow

HI

I am trying to add number to a variable every time, button was push but when it gets to 32000 it goes over flow.
Below is what i am trying to do:

unsigned long test_delay = 1000UL // initial value

if (digitalRead(3) == HIGH){

test_delay = (long) test_Delay + 100UL

}

any idea why and how to fix it

Thank you

I am able to add untill 32000 then it goes over flow

No, but watch your spelling and capitalization.

Post the rest of the code, where the actual problem can be found. Use code tags (</>).

d is NOT D

Mark

USE CODE TAGS! Edit your post and add them.

Shahreza:
I am trying to add number to a variable every time, button was push but when it gets to 32000 it goes over flow.

You did not add number to a variable

   if (digitalRead(push_inc) == HIGH) {


        Relay_ON_Interval =  100UL;   // it re-assign value every time
       if (Relay_ON_Interval > 60000)
         Relay_ON_Interval = 60000;

You check on the wrong variable

   if (digitalRead(push_inc) == HIGH) {

     for (int g = 0; g < 100; g++) {
       Relay_OFF_Interval++;
       if (Relay_ON_Interval > 10000)
         Relay_OFF_Interval = 10000;
     }

The code you posted doesnt seem to contain the snippet you were having difficulty with in the original post.. Are you sure you posted the right code?

Why not stick with unsigned long?

long unsigned previous_Millis = 0;
...
long previousLCDMillis = 0;    // for LCD screen update
long lcdInterval = 1000;
...
long unsigned i = 500;
...
long unsigned currentMillis = millis();

sorry I copy my code from my email and that was old one, the reason I change to see if that fix the problem, but in both cases does not go over 32k

all I want do is add 1000 to variable every time they press button.

You tell me how to do it

long

unsigned long

Either one will work.

First, fix the problems identified in reply #4.

Referring to your original post, you've already declared test_delay as unsigned long. So to add 100 to it every time a button is pressed, just need to use

test_delay += 100;

The main problem is that as the main loop processes over and over, 100 keeps getting added to test_delay over and over "while" the button is pressed.

Check the StateChangeDetection example included with the IDE to find out how to do this only once, "just" when the button is pressed or "just" when the button is released.