So basically I'm making 2 buttons turn on and off 2 different LEDs using debounce. I got that settled with one button to turn on and off 1 LED. But how do I make it so I can use the same lines but obviously different names of pins in Void loop?
So this is the one command line, but how do I make 2 commands with the if statement, may I have an example? Thanks
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int inPin = 22; // the number of the input pin
int inPin2 = 26;
int outPin1 = 13; // the number of the output pin
int outPin2 = 6;
int state = LOW; // the current state of the output pin
int reading; // the current reading from the input pin
int reading2;
int previous = HIGH; // the previous reading from the input pin
int previous2 = HIGH;
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
//===============================================================================================
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()
{
// 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);
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
doIt(outPin1);
}
else if (reading2 == HIGH && previous2 == LOW && millis() - time > debounce){
doIt(outPin2);
}
previous = reading;
previous2 = reading2;
time = millis();
}