#define REED_PIN 0 // 2 = D4 Pin connected to reed switch
#define REED_PIN2 2 // 1 = TX Pin connected to reed switch
#define BUT_UP 1 //Button for UP
#define BUT_DOWN 3 //Button for UP
#define BUTTON4 4
#define BUTTON5 5
#define BUTLED_UP 8 //LED on Button for UP
#define BUTLED_DOWN 9 //LED on Button for UP
#define LED6 6
#define LED7 7
#define LED_PIN 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(REED_PIN, INPUT_PULLUP); // Enable internal pull-up for the reed switch, so you don't need 10Ko resistor
pinMode(REED_PIN2, INPUT_PULLUP); // Enable internal pull-up for the reed switch, so you don't need 10Ko resistor
pinMode(BUT_UP, INPUT_PULLUP);
pinMode(BUT_DOWN, INPUT_PULLUP);
pinMode(BUTTON4, INPUT);
pinMode(BUTTON5, INPUT);
/* LED lampen */
pinMode(BUTLED_UP, OUTPUT);
pinMode(BUTLED_DOWN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
}
void loop() {
/* This area checks the state of the reed switch */
if (digitalRead(REED_PIN) == LOW) { //When reed_off is low, aka off, the switch is closed and thereby 'on'
digitalWrite(LED_PIN, 1); // Turn the LED on
etage = 2;
/* Resets both buttons and booleans on floor 2 */
digitalWrite(BUTLED_UP, 0);
etage2_wait_up = false;
// digitalWrite(BUTLED_DOWN, 0);
// etage2_wait_down = false;
}
else {
digitalWrite(LED_PIN, 0); // Turn the LED off
}
/* This area checks the state of buttons up and down */
if(digitalRead(BUT_UP) == 0){
digitalWrite(BUTLED_UP, 1);
etage2_wait_down = true;
}
// if(digitalRead(BUT_DOWN) == 0){
// digitalWrite(BUTLED_DOWN, 1);
// etage2_wait_down = true;
// }
/* This area checks the state of the reed switch */
if (digitalRead(REED_PIN2) == LOW) { //When reed_off is low, aka off, the switch is closed and thereby 'on'
digitalWrite(LED_PIN, 1); // Turn the LED on
etage2 = 2;
/* Resets both buttons and booleans on floor 2 */
// digitalWrite(BUTLED_UP, 0);
// etage2_wait_up = false;
digitalWrite(BUTLED_DOWN, 0);
etage2_wait_down = false;
}
else {
digitalWrite(LED_PIN, 0); // Turn the LED off
}
/* This area checks the state of buttons up and down */
// if(digitalRead(BUT_UP) == 0){
// digitalWrite(BUTLED_UP, 1);
// etage2_wait_down = true;
// }
if(digitalRead(BUT_DOWN) == 0){
digitalWrite(BUTLED_DOWN, 1);
etage2_wait_down = true;
}
if (digitalRead(BUTTON4) == LOW) {
digitalWrite(LED6, LOW);
} else {
digitalWrite(LED6, HIGH);
}
if (digitalRead(BUTTON5) == LOW) {
digitalWrite(LED7, LOW);
} else {
digitalWrite(LED7, HIGH);
}
}