Unsigned long problem

I am building a timeclock with multiple outputs.
Here is the part that I'm having problem with.
using DS3231 I read ss(seconds), mm(minutes) hh(hours) then convert it all to seconds. I'm getting readings > 4,000,000,000
1.8.14 Hourly Build 2021/01/29 11:33

unsigned long timecode;
int ss = 30;
int mm = 6;
int hh = 10;
void setup() {
timecode = ((ss) + (mm * 60) + (hh *3600));
//  = 36390
// 23:59:59 should = 86,399 maximum
Serial.begin(57600);
}

void loop() {
Serial.println(timecode);
timecode ++;

}

Try
timecode = ((ss) + (mm * 60UL) + (hh *3600UL));

Great works fine. thank you.

Ask if you need an explanation.

Found it. a 'ul' or 'UL' to force the constant into an unsigned long constant. Example: 32767ul

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.