#define ReedPin5 0 // 2 = D4 Pin connected to reed switch
#define ReedPin6 2 // 1 = TX Pin connected to reed switch
#define SwitchPin1 1 //Button for UP
#define SwitchPin2 3 //Button for UP
#define SwitchPin3 4
#define SwitchPin4 5
#define RelayPin1 8 //LED on Button for UP
#define RelayPin2 9 //LED on Button for UP
#define RelayPin3 6
#define RelayPin4 7
#define wifiLed 13 // LED pin
int etage;
int etage2;
//These booleans show is someone on this floor wants to go up and/or down
bool etage2_wait_up = false;
bool etage2_wait_down = false;
void setup() {
Serial.begin(9600);
/* Sensoren */
pinMode(ReedPin5, INPUT_PULLUP); // Enable internal pull-up for the reed switch, so you don't need 10Ko resistor
pinMode(ReedPin6, INPUT_PULLUP); // Enable internal pull-up for the reed switch, so you don't need 10Ko resistor
pinMode(SwitchPin1, INPUT_PULLUP);
pinMode(SwitchPin2, INPUT_PULLUP);
pinMode(SwitchPin3, INPUT_PULLUP);
pinMode(SwitchPin4, INPUT_PULLUP);
/* LED lampen */
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(wifiLed, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
}
void loop() {
/* This area checks the state of the reed switch */
if (digitalRead(ReedPin5) == LOW) { //When reed_off is low, aka off, the switch is closed and thereby 'on'
digitalWrite(wifiLed, HIGH); // Turn the LED on
etage = 2;
/* Resets both buttons and booleans on floor 2 */
digitalWrite(RelayPin2, LOW);
etage2_wait_up = false;
}
else {
digitalWrite(wifiLed, LOW); // Turn the LED off
}
/* This area checks the state of buttons up and down */
if(digitalRead(SwitchPin2) == LOW){
digitalWrite(RelayPin2, HIGH);
etage2_wait_down = true;
}
/* This area checks the state of the reed switch */
if (digitalRead(ReedPin6) == LOW) { //When reed_off is low, aka off, the switch is closed and thereby 'on'
// digitalWrite(wifiLed, HIGH); // Turn the LED on
etage2 = 2;
/* Resets both buttons and booleans on floor 2 */
digitalWrite(RelayPin3, LOW);
etage2_wait_down = false;
}
else {
digitalWrite(wifiLed, LOW); // Turn the LED off
}
/* This area checks the state of buttons up and down */
if(digitalRead(SwitchPin3) == LOW){
digitalWrite(RelayPin3, HIGH);
etage2_wait_down = true;
}
if (digitalRead(SwitchPin1) == LOW) {
digitalWrite(RelayPin1, HIGH);
} else {
digitalWrite(RelayPin1, LOW);
}
if (digitalRead(SwitchPin4) == LOW) {
digitalWrite(RelayPin4, HIGH);
} else {
digitalWrite(RelayPin4, LOW);
}
}