int Buup = 6;
int Budp = 5;
int Bbup = 4;
int Bbdp = 3;
int Bep = 8;
int Sup = 10;
int Sbp = 9;
int Buu, Bud, Bbu, Bbd, Be, Su, Sb;
int redLED = 12;
int greenLED = 13;
void setup()
{
Serial.begin(9600);
pinMode(Buup, INPUT_PULLUP);
pinMode(Budp, INPUT_PULLUP);
pinMode(Bbup, INPUT_PULLUP);
pinMode(Bbdp, INPUT_PULLUP);
pinMode(Bep, INPUT_PULLUP);
pinMode(Sup, INPUT_PULLUP);
pinMode(Sbp, INPUT_PULLUP);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
void loop()
{
Buu = !digitalRead(Buup);
Bud = !digitalRead(Budp);
Bbu = !digitalRead(Bbup);
Bbd = !digitalRead(Bbdp);
Be = !digitalRead(Bep);
Su = !digitalRead(Sup);
Sb = !digitalRead(Sbp);
//Serial.println(Buu);
//delay(500);
if(!Su && (Bbu == 1 || Buu == 1) && (Be + Bud + Bbd == 0))
{
digitalWrite(redLED, HIGH);
}
else
{
if(Be == 0)//emergency not pressed
{
if(!Sb)//Not in the bottom floor
{
if((Buu == 0) && (Bbu == 0)) //Upward pushbuttons in up or bottom floors were not pressed
{
if(Bud == 1 || Bbd == 1) //Downward pushbutton in up or bottom floors was pressed
{
digitalWrite(greenLED, HIGH);
}
else
{
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
}
}
}
}
}
}
Bottom Floor's Pushbuttons
Upper Floor's Pushbuttons
Upper floor state
Bottom floor state
Emergency