Interrupt variable exceeds volatile long's 8bit size

Prevent that from happening by turning off interrupts, make a copy of the variable, and use the copy. For example:

volatile long counts = 0;
...

//in loop

noInterrupts();
long count_copy = counts; //make a copy
interrupts();

Serial.println(count_copy); //display the copy
1 Like