The subroutine pwmread() reads the duration of the incoming pwm signal (just a replacement for pulseIn() function but with 1 microsecond resolution).
My question is:
How can I get "0" printed to the serial port with this sketch? It should be impossible (the if statement should prevent a "0" being printed) but it occurs!
KeithRB:
Man, I have to start looking for those. There seems to be a rash of them lately.
Simple solution
if( condition) …
MAY stop you from doing what everybody does once a while .
Just let the compiler evaluate without explicit check for ZERO, it is ONE of the few things “automation” is beneficial.
Vaclav:
Simple solution
if( condition) .....
MAY stop you from doing what everybody does once a while .
Just let the compiler evaluate without explicit check for ZERO, it is ONE of the few things "automation" is beneficial.
In this case no, because the following that advice, the OP would have written:
Delta_G:
You have a semicolon on the end of your if statement. That terminates the if block. Everything after that is going to be executed unconditionally.
Oh my God!
Quote from Einstein: "Two Things Are Infinite: the Universe and Human Stupidity"
I am very sorry for wasting your time. But mistakes like these are sometimes not easy to see, especially if it is your own code.
OP: These are what I call "flat forehead mistakes". It's where you see the error and then slam the heel of your hand to your forehead, saying something like: "How could I be so stupid?" Relax, most of us have fairly flat foreheads and you should expect your fair share. The good news is that it's unlikely you'll make this mistake again. The bad news is that you'll move on to more sophisticated bugs down the road. It's process we all go (went?) through.