So my serial imput is now working flawlessly, however, my checkButton() function is working less than desirable. It will occasionally trigger the code but very rarely will it register no matter what i try. I have tried two different iterations of the code, #7 has debounce, and #6 does not. Neither is working.
Here is the code snippets of the function in both sketches:
#6
void checkButton() {
int reading = digitalRead(buttonPin);
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
Serial.println("<Button>");
if ((toggle [1] == 1) || (toggle [1] == 2)) {
toggle [1] = 0;
}
else if (toggle [1] == 0) {
toggle [1] = 1;
}
}
}
#7
void checkButton() {
int reading = digitalRead(buttonPin);
buttonState = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
Serial.println("<Button>");
if ((toggle [1] == 1) || (toggle [1] == 2)) {
toggle [1] = 0;
}
else if (toggle [1] == 0) {
toggle [1] = 1;
delay(500);
}
}
}
}
lastButtonState = reading;
}
Below i will attach the full codes.
MM_Sorter_shift_toggle_servo_count7.ino (10.4 KB)
MM_Sorter_shift_toggle_servo_count6.ino (10.1 KB)