Program malfunctioning on even counts

Hi everyone,

I made a program to fire a relay and then turn a motor when a state change is detected from a device. The device also has a quantity that the user inputs and it will only function for that amount and then disable itself.

My problem is that when I enter an EVEN number for the quantity on the device, it works perfectly. But when I enter any odd number quantity, the motor will turn 1 extra time.

Can someone please look at my program and let me know what I can do to prevent this?

SEMI_AUTO_FINAL.ino (492 Bytes)

Welcome to the Forum. Please read the two posts by Nick Gammon at the top of this Forum for guidelines on the proper way to post here, especially the use of code tags to post source code. Many readers here will not download a source file; they prefer to review it in the code tag space.

You appear to have posted the wrong sketch (also, please use code tags so we don't have to download your attachment and open it to see it). You say that the problem relates to user input, but the sketch you posted has no provision for user input.

mrneedles:
Hi everyone,

I made a program to fire a relay and then turn a motor when a state change is detected from a device. The device also has a quantity that the user inputs and it will only function for that amount and then disable itself.

My problem is that when I enter an EVEN number for the quantity on the device, it works perfectly. But when I enter any odd number quantity, the motor will turn 1 extra time.

Can someone please look at my program and let me know what I can do to prevent this?

Historically, those symptoms point to the low order bit somewhere being either tested improperly, or being changed accidentally. Even number will always have a zero in the low order bit, while odd numbers always have a one.

Does your sketch do anything like that? No, I won't download your attachment, either.

Paul

What Arduino are you using?
How are the numbers entered ?

...R