Here's your hanging offense ![]()
if( counter != temp ){
Serial.println (counter);
temp = counter;
}
Counter is touched in an interrupt and it's four bytes. Consequently, it may change behind the scenes while you're looking at it. What you need is:
noInterrupts() ;
if( counter != temp ){
Serial.println (counter);
temp = counter;
}
interrupts() ;
Although it would be better to move the Serial.print out of that section.