Skip to main content
2 of 3
added 700 characters in body
Ikbel
  • 620
  • 4
  • 13

Edit: Use the code below as it is, it's working for me:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int inPin = 22; 
int inPin2 = 26;
int outPin1 = 13;    
int outPin2 = 6;

int state1 = HIGH;
int state2 = HIGH;
int reading;     
int reading2;
int previous = HIGH; 
int previous2 = HIGH;

int debounce = 150;   // the debounce time, increase if the output flickers

//===============================================================================================
void doIt(int outPin, int state)
{
  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()
{
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("System Activated");
  //
  lcd.setCursor(0, 1);
  lcd.print("Ready...");

  pinMode(inPin, INPUT);
  pinMode(outPin1, OUTPUT);
  pinMode(inPin2, INPUT);
  pinMode(outPin2, OUTPUT);

  Serial.begin(9600);
  Serial.println("System Activated");
  Serial.println("Made by Mateo Holguin");
  Serial.println("0 = Light is Off | 1 = Light is On");
  Serial.println("=======================================");
}

//===============================================================================================

void loop()
{
  reading = digitalRead(inPin);
  reading2 = digitalRead(inPin2);
  delay(debounce);

  if (reading == HIGH)
  {
    state1 = !state1;
    doIt(outPin1, state1);  
  }
  else if (reading2 == HIGH){
    state2 = !state2;
    doIt(outPin2, state2);
  }
}
Ikbel
  • 620
  • 4
  • 13