Elevator model

I liked to do for a school project in one elevator model with sensors and buttons.
Would like to get suggestions to do .... :slight_smile:
Thanks

I'd start with reading up on state machines, since I don't see you being successful without a state machine approach.

Sort of thing like state = parked with doors closed, input = button push on this floor, action = open door, state = parked with open doors etc etc etc

I found these sites useful:

http://www.objectmentor.com/resources/articles/umlfsm.pdf

http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html
http://hacking.majenko.co.uk/finite-state-machine

I remember doing this in school. I came up with a quite elegant solution requiring only 4 states and latch for the buttons. The solution is scalable for any number of floors.

Checking is done in one direction. If there is a latched button press in that direction the move state is entered. When the sensors indicate that the latched destination is reached the state is transferred to the delay state and the latch for that floor is reset. After the delay a new check is made for more destinations in the same direction. If there are the state is changed back to the move state, otherwise the direction is changed and the check state is entered. If there are no latched destinations the direction is changed again and again until a latched destination is discovered.

elevator state machine.png

Some of the suggested reading about state machines (and even the name itself) can give the impression that is is a complex subject and not for beginners.

The reality is that it can be very simple for simple projects. It just means having one or more variables that record what stage (or state) the program has reached.

While I don't think I used the term "state machine" in this Thread about Planning and Implementing a Program the demo code does use state variables all over the place - for example for the state of a flashing LED or the state of a switch.

...R