The Arduino uno Takes 20 seconds to start

im Have a strange issue with my arduino Uno. it seems to work normally but 15 second in, it starts running really quickly. i set up a timer loop using milis and it runs once every 5 sesconds like it should but suddenly, it starts running 100 times+ a second. massive amount of prints occur.

i thought it was my code but i commented everything out. only loop variables and serial.begin();

whats odd is that if i do this in an empty sketch, its fine but if i use my sketch with everything commented out, this problem occur. Any ideas? any by eveything commented out i do mean everything. not even global vars. everything except loop var and serial.begin().

i even went all out and deleted everything instead of commenting it out. still same. i Ended up copying the code to a new sketch, but nothing. any ideas?

loop(){

  MessTime=millis();
  
  if(MessTime-HoldTime>interval){
      HoldTime=MessTime;

      }

  }

That code will not tell you what is going on.

(deleted)

spycatcher2k: Post a sketch that shows this - make it the smallest one you find show this behaviour.

its all good. the Problem was that i used int instead of unsigned longs. seems to work after changing that

But where you used int? Please, be more specific about your mistake. It can be helpful for other people.

This example demonstrates why you should always post full sketches too - as the problem is obvious from the full sketch, with variable declarations, but not visible in the snippet you posted.

Budvar10: But where you used int? Please, be more specific about your mistake. It can be helpful for other people.

i defined MessTime,HoldTime and interval as global ints and they should be unsigned longs.