const int rotaryPins[] = {2, 3, 4, 5, 6, 7}; // Rotary switch inputs
const int outputs[] = {8, 9, 10, 11, 12, 13}; // Arduino outputs
const int debounceDelay = 50; // Debounce time in milliseconds
const int momentaryLowDuration = 1500; // Duration of low output in milliseconds
int lastStates[6]; // Stores the last states of the rotary pins
unsigned long lastDebounceTimes[6]; // Stores the last debounce times
void setup() {
for (int i = 0; i < 6; i++) {
pinMode(rotaryPins[i], INPUT_PULLUP); // Rotary switch input with pull-up resistor
pinMode(outputs[i], OUTPUT); // Set output pins
lastStates[i] = digitalRead(rotaryPins[i]); // Initialize last states
digitalWrite(outputs[i], HIGH); // Ensure outputs are initially high
}
}
void loop() {
for (int i = 0; i < 6; i++) {
int currentState = digitalRead(rotaryPins[i]);
if (currentState != lastStates[i] && millis() - lastDebounceTimes[i] > debounceDelay) {
lastDebounceTimes[i] = millis();
lastStates[i] = currentState;
if (currentState == LOW) { // Position change detected
digitalWrite(outputs[i], LOW);
delay(momentaryLowDuration);
digitalWrite(outputs[i], HIGH);
}
}
}
}