I'm pretty sure the last switch statement should just look like:
default: //no movement currently
if(openBtnCount > 0) {
openMode = 1;
movementCount = openTime;
digitalWrite(closeBtnOut, LOW);
digitalWrite(openBtnOut, HIGH);
} else if(closeBtnCount > 0) {
openMode = 2;
movementCount = closeTime;
digitalWrite(closeBtnOut, HIGH);
digitalWrite(openBtnOut, LOW);
} else {
allStop();
}
I'm also pretty sure the "movementCount -= loopInterval;" lines shouldn't be in the case 3 and case 4 and default switches. They are unnecessary in case 3 and 4, and constantly decremented when there is no motion in the default case.
|