A couple of further comments on the code in post #43
There is no need to use 3 variable for the frequency. Current and previous values are enough
You are printing and erasing text that will never change. This is not necessary, inefficient and should not be done