I've got a simple program that prints out a count for every 5000 iterations. I've set the variable to long which should be able to hold up to 2,147,483,647
int count;
void setup() {
Serial.begin(115200);
}
void loop() {
for (long x = 0; x < 32768; x++)
{
count++;
if ((count % 5000) == 0)
{
Serial.println(count);
delay(1000);
}
}
}
However I'm seeing the following printed out:
5000
10000
15000
20000
25000
30000
-30000
-25000
-20000
-15000
-10000
-5000
Clearly I'm missing something or don't understand long very well.
I've tried unsigned long but that didn't make any difference.