Lines 31 - 34 are an attempt to constrain the value of 'rpm' to between 0 and 500.
It doesn't work. Well, it sort of works but I need better than 'sort of'.
If I dial it down to 0 and keep going, it does indeed stay on zero. But, it saves those zeros up so if I want to increase the value I have to dial out all of those zeros before the value starts increasing again.
At the top end, it does the same thing in the opposite direction.
Suggestions please.
I don't keep code that fails so I really don't have anything to show.
There are no external pullups.
The code works excellent until I try to constrain it.
That helped for counter > 20. I'd been trying something similar but got slightly weird results. The rpm count would increase to 525 then go to 475 on the way down. Goofy but acceptable. Your code gives the proper numbers.
The bigger problem is at counter < 0. Counter never gets to < 0 it goes to 65535 (x0FFFF).
It seems this code just goes around in a big circle (no negative numbers) . I tried counter = 65535 but that just returns a string of zeros.
At this point, I'm looking for a library that appeals to me.
I stand corrected. Changing to a signed variable does now, indeed, give me negative numbers. I was misreading the output. I think a bit more coding and I'll be where I'd like to be. I'll keep you updated.