#define REED_PIN 0 // Pin connected to reed switch
#define LED_PIN 13 // LED pin
#define BUT_UP 1 //Button for UP
#define BUTLED_UP 2 //LED on Button for UP
#define BUT_DOWN 3 //Button for UP
#define BUTLED_DOWN 4 //LED on Button for UP
int etage;
//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(BUT_UP, INPUT_PULLUP);
pinMode(BUT_DOWN, INPUT_PULLUP);
/* LED lampen */
pinMode(BUTLED_UP, OUTPUT);
pinMode(BUTLED_DOWN, OUTPUT);
pinMode(LED_PIN, 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_up = true;
}
if(digitalRead(BUT_DOWN) == 0){
digitalWrite(BUTLED_DOWN, 1);
etage2_wait_down = true;
}
}