Code acting weird

Because while the signal is HIGH, you keep resetting CCPM to millis(), but you DON'T reset COPM. Eventually millis() - COPM reaches COI and you call ReturnSeq().

Same for the signal being LOW: You keep resetting COPM to millis(), but you DON'T reset CCPM. Eventually millis() - CCPM reaches CCI and you call PickedupSeq().

What you need is State Change Detection, like in the Arduino example: File->Examples->02.Digital->StateChangeDetection. Reset the timer only when the state CHANGES.

1 Like