// Latched Rotary Swtich to Momentary Out for Centroid BOB Jog Controls.
//DIP Switch is replacing rotary latched switch in this example.
//Press play button on simulation and select switch 1-3 to see momentary output.
//Momentary low output set for 500 ms for representation.
//Input from rotary (DIP) switch remains low, only one momentary pulse until switch input to Arduino is changed and provides another momentary output.
//LEDs are for visual representation only, pins 5-7 would connect directly to BOB Inputs for Jog select speed.
const int inputPin1 = 2; // Input pin 1
const int inputPin2 = 3; // Input pin 2
const int inputPin3 = 4; // Input pin 3
const int outputPin1 = 5; // Output pin 1
const int outputPin2 = 6; // Output pin 2
const int outputPin3 = 7; // Output pin 3
// Duration for the momentary low output (in milliseconds)
const unsigned long lowDuration = 500; // Momentary low duration set to 500ms
// Variables to track the previous state of the input pins
bool lastInput1 = HIGH;
bool lastInput2 = HIGH;
bool lastInput3 = HIGH;
void setup() {
// Initialize input pins
pinMode(inputPin1, INPUT_PULLUP);
pinMode(inputPin2, INPUT_PULLUP);
pinMode(inputPin3, INPUT_PULLUP);
// Initialize output pins
pinMode(outputPin1, OUTPUT);
pinMode(outputPin2, OUTPUT);
pinMode(outputPin3, OUTPUT);
// Set output pins to HIGH initially
digitalWrite(outputPin1, HIGH);
digitalWrite(outputPin2, HIGH);
digitalWrite(outputPin3, HIGH);
}
void loop() {
// Read the input pins
bool input1 = digitalRead(inputPin1);
bool input2 = digitalRead(inputPin2);
bool input3 = digitalRead(inputPin3);
// Check for falling edges and trigger the corresponding output
if (lastInput1 == HIGH && input1 == LOW) {
momentaryLow(outputPin1); // Pin 5 for input pin 2
}
if (lastInput2 == HIGH && input2 == LOW) {
momentaryLow(outputPin2); // Pin 6 for input pin 3
}
if (lastInput3 == HIGH && input3 == LOW) {
momentaryLow(outputPin3); // Pin 7 for input pin 4
}
// Update the last input states
lastInput1 = input1;
lastInput2 = input2;
lastInput3 = input3;
}
// Function to set a pin low for a moment
void momentaryLow(int pin) {
digitalWrite(pin, LOW); // Set pin to LOW
delay(lowDuration); // Wait for the defined duration (500 ms)
digitalWrite(pin, HIGH); // Set pin back to HIGH
}