Hi all, newbee to Arduino and the last language I programmed was on a Trash-80!
Anyway, need some help with whays not working.
Scope: Have 5 windows that open and shut using 24 VDC actuators. Have my Arduino Mega hooked into a 16 channel relay board and have written the following code. Its starts of fine, but with multiple push button 'pushes' things get confused (will open then shut etc).
I'm thinking:
-
I'm not putting a baseline on the windows so they know where they should be, or
-
I need some kind of lock-out on the functions so is if the button is pushed while its executing an all-open or all-close it ignores it.
Any insights??
const int Lounge_Open = 46;
const int Office_Open = 47;
const int Matthew_Open = 48;
const int James_Open = 49;
const int Lounge_Close = 50;
const int Office_Close = 51;
const int Matthew_Close = 52;
const int James_Close = 53;
const int All_Open_Button = 22;
const int All_Close_Button = 23;
int val_Open = 0;
int val_Close = 0;
void setup() {
pinMode(All_Open_Button,INPUT_PULLUP);
pinMode(All_Close_Button,INPUT_PULLUP);
pinMode(Lounge_Open, OUTPUT);
pinMode(Office_Open, OUTPUT);
pinMode(Matthew_Open, OUTPUT);
pinMode(James_Open, OUTPUT);
pinMode(Lounge_Close, OUTPUT);
pinMode(Office_Close, OUTPUT);
pinMode(Matthew_Close, OUTPUT);
pinMode(James_Close, OUTPUT);
digitalWrite(Lounge_Open, HIGH);
digitalWrite(Office_Open, HIGH);
digitalWrite(Matthew_Open, HIGH);
digitalWrite(James_Open, HIGH);
digitalWrite(Lounge_Close, HIGH);
digitalWrite(Office_Close, HIGH);
digitalWrite(Matthew_Close, HIGH);
digitalWrite(James_Close, HIGH);
}
void loop() {
val_Open = digitalRead(All_Open_Button);
val_Close = digitalRead(All_Close_Button);
if (val_Open == LOW) All_Open();
if (val_Close == LOW) All_Close();
}
void All_Close() {
digitalWrite(Lounge_Close, LOW);
digitalWrite(Office_Close, LOW);
digitalWrite(Matthew_Close, LOW);
digitalWrite(James_Close, LOW);
delay(10000);
digitalWrite(Lounge_Open, HIGH);
digitalWrite(Office_Open, HIGH);
digitalWrite(Matthew_Open, HIGH);
digitalWrite(James_Open, HIGH);
digitalWrite(Lounge_Close, HIGH);
digitalWrite(Office_Close, HIGH);
digitalWrite(Matthew_Close, HIGH);
digitalWrite(James_Close, HIGH);
}
void All_Open(){
digitalWrite(Lounge_Open, LOW);
digitalWrite(Office_Open, LOW);
digitalWrite(Matthew_Open, LOW);
digitalWrite(James_Open, LOW);
delay(10000);
digitalWrite(Lounge_Open, HIGH);
digitalWrite(Office_Open, HIGH);
digitalWrite(Matthew_Open, HIGH);
digitalWrite(James_Open, HIGH);
digitalWrite(Lounge_Close, HIGH);
digitalWrite(Office_Close, HIGH);
digitalWrite(Matthew_Close, HIGH);
digitalWrite(James_Close, HIGH);
}
