impulseInputs.ino 961 B

1234567891011121314151617181920212223
  1. void checkInputStates() {
  2. for (byte i = 0; i < sizeof(pulseInPins); i++) {
  3. byte _inputCurrentState = digitalRead(pulseInPins[i]);
  4. if (_inputCurrentState == LOW && pulseInLastState[i] == HIGH) {
  5. pulseInLastDebounceTime[i] = millis();
  6. pulseAlreadyDetected[i] = false;
  7. pulseInLastState[i] = _inputCurrentState;
  8. }
  9. else if (_inputCurrentState == LOW && pulseInLastState[i] == LOW) {
  10. if ( (millis() - pulseInLastDebounceTime[i]) > debounceDelay && !pulseAlreadyDetected[i]) {
  11. //if ( (millis() - pulseInLastDebounceTime[i]) > debounceDelay ) {
  12. pulseInLastDebounceTime[i] = millis();
  13. pulseAlreadyDetected[i] = true;
  14. increaseCounter(i);
  15. }
  16. }
  17. else if (_inputCurrentState == HIGH && pulseInLastState[i] == LOW) {
  18. if ( (millis() - pulseInLastDebounceTime[i]) > debounceRecoveryDelay ) {
  19. pulseInLastState[i] = _inputCurrentState;
  20. }
  21. }
  22. }
  23. }