const int REVERSE_PIN = 3; // Pin connected to the Reverse switch
const int REVERSE_LED_PIN = 7; // Pin connected to the Reverse Switch LED
// Variables to track the state of the reverse switch
bool reverseState = false;
void setup() {
pinMode(REVERSE_PIN, INPUT_PULLUP); // Set the Reverse pin as input with internal pull-up resistor
pinMode(REVERSE_LED_PIN, OUTPUT); // Set the Reverse Switch LED pin as output
Serial.begin(9600); // Initialize serial communication for debugging
Serial.print("test");
}
void loop() {
int reverseCurrentState = digitalRead(REVERSE_PIN);
// Debounce logic for the Reverse switch
if (reverseCurrentState == LOW && reverseState == HIGH) {
delay(50); // Wait for 50ms to debounce
reverseCurrentState = digitalRead(REVERSE_PIN); // Read the state again after debounce
if (reverseCurrentState == LOW) {
reverseState =!reverseState; // Toggle the state
Serial.print("Reverse switch state: ");
Serial.println(reverseState? "ON" : "OFF");
// Control the Reverse Switch LED based on the reverseState
digitalWrite(REVERSE_LED_PIN, reverseState? HIGH : LOW); // Turn on/off the Reverse Switch LED
}
}
}