variable types - printing to OLED

I have a countdown timer that counts down the hours, minutes and seconds to zero calculated from a decrementing total seconds value.

int h = 0;
int m = 0;
int s = 0;
long unsigned int remainingSeconds = 122600;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop(){

TimeCalc(remainingSeconds);

Serial.print(h); Serial.print(" ");Serial.print(m); Serial.print(" ");Serial.println(s);
remainingSeconds --;
}

void TimeCalc( long unsigned int seconds ) {
  uint32_t t = seconds;

  s = t % 60;

  t = (t - s) / 60;
  m = t % 60;

  t = (t - m) / 60;
  h = t;
}

The code above works fine - the serial monitor.. however I am getting garbage writing to the OLED screen when I start the countdown above 9 hours and 6 minutes.

changing the int variables to uint16_t I'm able to get to 18 hours 12 minutes.. above that, the garbage starts again. Going to uint32_t makes no difference...

anyone know what might be going on here?

1 Like

Ok, so you post some code which works
then ask why some other code (that you don't post) doesn't work.

C'mon give us a break

Yours,
TonyWilk

long unsigned int remainingSeconds = 122600;

The typical order of qualifiers is signed/unsigned size type, so this is usually written as

unsigned long int remainingSeconds = 122600;

Of course, since you can't have a long float or a long char or a long struct, the type, when long is supplied, can only be int, so that is not usually supplied.

unsigned long remainingSeconds = 122600;