Reed switch and Debounce button

Hello.

I'm trying too make a automatic controlled window which uses 2 toggle buttons and 2 relays for the open and close function.
LED_PIN1 and LED_PIN2 will be replaced with relays so just for prototyping im using leds...
Code im using is this:

#include <Bounce2.h>


#define BUTTON_PIN1 2               // WE WILL attach() BUTTON 1 TO THE FOLLOWING PIN 2 setup()
#define BUTTON_PIN2 3               // WE WILL attach() BUTTON 2 TO THE FOLLOWING PIN 3 setup()
#define LED_PIN1 8                  // WE WILL attach() LED 1 TO THE FOLLOWING PIN 8 setup()
#define LED_PIN2 9                  // WE WILL attach() LED 2 TO THE FOLLOWING PIN 9 setup()
Button button1 = Button();          // INSTANTIATE A Button 1 OBJECT
Button button2 = Button();          // INSTANTIATE A Button 2 OBJECT 

int ledState1 = LOW;                // SET A VARIABLE TO STORE THE LED 1 STATE
int ledState2 = LOW;                // SET A VARIABLE TO STORE THE LED 2 STATE
int reedPin = 12;


void setup() 
{
  button1.attach( BUTTON_PIN1, INPUT);          // USE BUTTON PIN 1
  button1.interval(5);                          // DEBOUNCE INTERVAL IN MILLISECONDS
  button1.setPressedState(LOW);                 // INDICATE THAT THE LOW STATE CORRESPONDS TO PHYSICALLY PRESSING THE BUTTON

  button2.attach( BUTTON_PIN2, INPUT);          // USE BUTTON PIN 2
  button2.interval(5);                          // DEBOUNCE INTERVAL IN MILLISECONDS
  button2.setPressedState(LOW);                 // INDICATE THAT THE LOW STATE CORRESPONDS TO PHYSICALLY PRESSING THE BUTTON

 
  
  pinMode(reedPin,INPUT);
  pinMode(LED_PIN1,OUTPUT);                   //LED PIN 1 IS AN OUTPUT
  pinMode(LED_PIN2,OUTPUT);                   //LED PIN 2 IS AN OUTPUT
  digitalWrite(LED_PIN1,ledState1);           //WRITE LED PIN 1 STATE
  digitalWrite(LED_PIN2,ledState2);           //WRITE LED PIN 2 STATE

}


void loop() 
{
  button1.update();                           // UPDATE THE BUTTON 1, YOU MUST CALL THIS EVERY LOOP
  if ( button1.pressed() )                    //IF BUTTON 1 IS PRESSED
    {
    ledState1 = !ledState1;                   //SET ledState 1 TO THE OPPOSITE OF ledState 1
    digitalWrite(LED_PIN1,ledState1);         //WRITE THE NEW ledState 1
    }



  button2.update();                           // UPDATE THE BUTTON 2, YOU MUST CALL THIS EVERY LOOP
  if ( button2.pressed() )                    //IF BUTTON 2 IS PRESSED
    {
    ledState2 = !ledState2;                   //SET ledState 1 TO THE OPPOSITE OF ledState 2
    digitalWrite(LED_PIN2,ledState2);         //WRITE THE NEW ledState 2
    }

}

I want too add a "fully open" and "fully closed" sensor so i decided too use reed switches at the very botton end and at the very top of the window. Generaly speaking, 2 stop sensors / switches.
Maybe use something else besides reed switches?
Im not asking for a direct "Ready for use" code as an answer.
Looking for some general guidance and thats all (obviously i'm lacking some knowlege at that... ).

Thanks

Maybe use something else besides reed switches?

Hall effect switches do not bounce. How to use Hall Effect switch with Arduino.

Limit switches don't need to be debounced. :slight_smile: