long data type problem

Hello Everyone, I am having trouble with a long data type in my code. I initialize the variable as a long, but the program keeps interpreting it as an integer. I know this because if there is a number > ~32000, it rolls over to -32536

I have included only the lines of code that are relevant...

long SpecimenHeatTime; // seconds remaining in the maintain heat mode (300 = 5 minutes)
long TR; // time remaining
long BeenHeating

void setup() {

SpecimenHeatTime = 33*1000; // seconds remaining in the maintain heat mode (300 = 5 minutes)
TR = SpecimenHeatTime; // time remaining
BeenHeating = 0;
}

void loop() {
Serial.print("toplevel "); Serial.println(TR); Serial.println(SpecimenHeatTime); Serial.println(BeenHeating); Serial.println(WakeUpTime); //debug 2/3/2012
}
;

SpecimenHeatTime = 33*1000; // seconds remaining in the maintain heat mode (300 = 5 minutes)

33 is an int. 1000 is an int. 33 * 1000 is, therefore, an int. Oops. it doesn't fit in an int, so it gets mangled.

Then, the compiler sees that you want to save the mangled value in a long. Well, the good news is that it fits.

SpecimenHeatTime = 33L*1000L;

is what you need to do.

By the way, your comment doesn't match the code. Ditch comments that add nothing.

Thanks Paul, that solved the issue.

Per the comments, they don’t get changed or updated every time i try something new in the code and re-upload

Per the comments, they don't get changed or updated every time i try something new in the code and re-upload

I understand that comments do not get updated. The comments, though, should reflect what the code is doing. Stating the obvious doesn't add anything meaningful. Those are the comments that are least likely to get updated when the code changes.

I use two styles with comments.

// Comments like this are used to describe what the program is doing // They provide an overview of the program structure or a specific block if(someConditional) // Comments here show pitfalls or specific issues

I think comments are useful, but when they don't add anything, the delete key is the most useful key to use.