Skip to main content
1 of 3
Ikbel
  • 620
  • 4
  • 13

This might be ugly, but it should do what you want:

int inPin1; // Assign it to the First Button
int inPin2; // Assign it to the Second Button

int time1, time2;
const int debounce = 20; // Set it to the value you want
int state;

int outPin1; // Assign it to the First LED
int outPin2; // Assign it to the Second LED

int reading1, reading2;
int previous1, previous2;

/* The rest of your declarations */

void doIt(int outPin)
{
    Serial.print("Button Switch State Change:");
    if (state == HIGH) state = LOW;
    else state = HIGH;      
    Serial.println(state);
    lcd.clear();
    lcd.print("Zone1|State: ");
    lcd.print(state ? F("On") : F("Off"));
    Serial.print(state ? F("On") : F("Off"));
    digitalWrite(outPin, state);  
}

void setup(){
  pinMode(outPin1, OUTPUT);
  pinMode(outPin2, OUTPUT);
  
  
}

void loop()
{
  
  reading1 = digitalRead(inPin1);
  reading2 = digitalRead(inPin2);
  if (reading1 == HIGH && previous1 == LOW && millis() - time1 > debounce){
    doIt(outPin1);
  }
  else if (reading2 == HIGH && previous2 == LOW && millis() - time2 > debounce){
    doIt(outPin2);
  }    
    previous1 = reading1;
    previous2 = reading2;
    time1 = millis();
    time2 = millis();
  
}
Ikbel
  • 620
  • 4
  • 13