so it has been any days just trying to get to where i am now and if some one could help me feel in what i need and all so show me how in text in my file would help as i still have alot to add
at this time i am trying to get a lighting system working from a set of buttons and relays
i have 2 sets of lighting 12vdc and 110ac lighting that i want to work from one button
loop
push button one time to
pin 6 on
again to make
pin 6 and 7 come on
again to make
pin 6 and 7 off Or just a timed long press for 6 and 7 to go off so you can go right to off from step 1 if need be
all so as it is now if i hold the button to long the lights come on and off so i need to add a delay or code so it dos not do this
all so i have 2 buttons just not in the same place as you can see in my code so the 2ed button can work like pin 6 but on the other side of the home
i am trying to under stand the IF and ELSE but i just being so new at this cant see what i need or where to start
thanks for any help in helping me under stand what i am doing
...
int hallway = 11;
int doorway = 12; // this is working
int relay110 = 7;
int relayout = 5;
int relay12v = 6; // this is working
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// 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 setup()
{
pinMode(doorway, INPUT);
pinMode(hallway, INPUT);
pinMode(relay12v, OUTPUT);
pinMode(relayout, OUTPUT);
pinMode(relay110, OUTPUT);
}
void loop()
{
reading = digitalRead(hallway);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(relay12v, state);
previous = reading;
reading = digitalRead(doorway);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(relay12v, state);
previous = reading;