Question: Help to do flowchart for this coding #include //Include the Liquid Crystal Library LiquidCrystal lcd(11,10,5,4,3,2); //Create Liquid Crystal Object called LCD int f=0; void setup()
Help to do flowchart for this coding
#include//Include the Liquid Crystal Library LiquidCrystal lcd(11,10,5,4,3,2); //Create Liquid Crystal Object called LCD int f=0; void setup() { pinMode(13,INPUT); // Button 1 pinMode(12,INPUT); // Button2 pinMode(9,OUTPUT); // Motor direction pinMode(8,OUTPUT); lcd.begin(16,2); //Initialize LCD as 16x2 display lcd.clear(); lcd.setCursor(0,0); } void loop() { delay(2000); // In order to control both switches a delay of 2 seconds is provided so within this time required switch combination must be selected if(digitalRead(13)==0 && digitalRead(12)==0) // If both switches are open, then the elevator must be in Floor 0, so check what is the current floor number { if(f==0) // If floor number is 0, then no need to move elevator, so motor is Off { digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 0"); delay(100); f=0; } else if(f==1) // If floor number is 1, then the elevator must go down, 1 floor below, so motor rotates backward for 5 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 1"); // Print that initially the elevator in floor 1 digitalWrite(9,LOW); // Elevator going down digitalWrite(8,HIGH); delay(5000); digitalWrite(9,LOW); // After 5 seconds motor is Off digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 0"); // Print that currently elevator is in floor 0 f=0; } else if(f==2) // If floor number is 2, then the elevator must go down, 2 floors below, so motor rotates backward for 10 seconds { { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 2"); // Print that initially the elevator in floor 2 digitalWrite(9,LOW); // Elevator goes down digitalWrite(8,HIGH); delay(10000); digitalWrite(9,LOW); // After 10 seconds elevator reached on floor 0 digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 0"); f=0; } else // If floor number is 3, then the elevator must go down, 3 floors below, so motor rotates backward for 15 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 3"); digitalWrite(9,LOW); digitalWrite(8,HIGH); delay(15000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 0"); f=0; } } if(digitalRead(13)==0 && digitalRead(12)==1) // If SW0 is closed and SW1 is open then the elevator must be in floor 1 { if(f==0) // If the elevator is in floor 0 , currently then it must go up , 1 floor , so motor rotates forward for 5 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 0"); digitalWrite(9,HIGH); digitalWrite(8,LOW); delay(5000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 1"); f=1; } else if(f==1) // If the current floor is 1, then elevator must remain in that floor , so Motor off { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 1"); digitalWrite(9,LOW); digitalWrite(8,LOW); delay(100) ; f=1; } else if(f==2) // If the elevator is in floor 2, then it must go down , to floor 1, so motor rotates backward for 5 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 2"); digitalWrite(9,LOW); digitalWrite(8,HIGH); delay(5000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 1"); f=1; } else // If the elevator is in floor 3, then it must go 2 floors down, so motor rotated backward for 10 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 3"); digitalWrite(9,LOW); digitalWrite(8,HIGH); delay(10000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.print("In floor 1"); lcd.clear(); lcd.setCursor(0,0); f=1; } } if(digitalRead(13)==1 && digitalRead(12)==0) // If SW1 is closed and SW0 is open , then elevator must be in floor 2 { if(f==0) // If the elevator is in floor 0, then it must go upwards, so rotate motor forward for 10 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 0"); digitalWrite(9,HIGH); digitalWrite(8,LOW); delay(10000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.print("In floor 2"); lcd.clear(); lcd.setCursor(0,0); f=2; } else if(f==1) // If the elevator is in floor 1 then rotate motor forward for 5 seconds to reach at floor 2 { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 1"); digitalWrite(9,HIGH); digitalWrite(8,LOW); delay(5000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 2"); f=2; } else if(f==2) // If the elevator is in floor 2, then no need to rotate, so motor is off { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 2"); digitalWrite(9,LOW); digitalWrite(8,LOW); delay(100); f=2; } else // If elevator is in floor 3, then it must go down, so motor rotates backward for 5 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 3"); digitalWrite(9,LOW); digitalWrite(8,HIGH); delay(5000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 2"); f=2; } } if(digitalRead(13)==1 && digitalRead(12)==1) // If both switches are closed then elevator must be in floor 3 { if(f==0) // If elevator is in floor 0, then it must go up by rotation of motor in forward direction for 15 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 0"); digitalWrite(9,HIGH); digitalWrite(8,LOW); delay(15000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 3"); f=3; } else if(f==1) // If elevator is in floor 1, then it must be in floor 3, so motor must rotate forward for 10 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 1"); digitalWrite(9,HIGH); digitalWrite(8,LOW); delay(10000); digitalWrite(9,LOW); digitalWrite(8,LOW); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 3"); f=3; } else if(f==2) // If elevator is in floor 2, then motor must rotate forward for 5 seconds { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 2"); digitalWrite(9,HIGH); digitalWrite(8,LOW); delay(5000); lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 3"); f=3; } else // If elevator is in floor 3, motor is Off { lcd.clear(); lcd.setCursor(0,0); lcd.print("In floor 3"); digitalWrite(9,LOW); digitalWrite(8,LOW); delay(100); f=3; } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
