Square wave based on falling edge of alternative pulse of upcoming RPM square wave
There are some things you shouldn't be doing within an interrupt service routine (ISR) like countRPM():


Don't call the millis() function. It depends on other interrupts which will be disabled during the execution of your ISR.
Don't call digitalWrite or any other functions
Don't use execution cycles hungry operators like % (modulo). To obtain modulo 2, just use a bit mask for the LSB.


What you should actually be doing within the ISR is just setting/resetting a flag or variable. Then, do all your stuff in the loop() function according the value of the flag or variable.