Once you understand the control algorithm you want to use, you can think about implementing that in code. But you need to understand the algorithm first.

Imagine that you are a lift operator. Each sensor you listed operates an indicator lamp that you can see - you have switches to make the lift go up or down and open/close the doors. Also assume that your short term memory is useless - you have to write everything down to remember it. How would you go about operating the lift?

I only provide help via the forum - please do not contact me for private consultancy.

- 4 floors- 7 magnetics sensors (4 to stop the lift when arrived to the floor and 3 between to slow it before the stop)- 4 contacts switches to verify if the doors are closed- 4 contact switches to verify that the Lock is activated- 10 buttons to call the lift (1 at level 1 (you can just go up) + 1 at level 4 (you can just go down) + 2 buttons at level 2 + 2 button at level 3 + 4 button inside the hoist

I don't understand what you mean with "Also assume that your short term memory is useless". I would like to store if someone call the lift when the lift is already in use.

I don't understand what you mean with "Also assume that your short term memory is useless". I would like to store if someone call the lift if te lift is already in use.

I want you to write down the things you would need to remember in order to operate the lift, to force you to think about what things you need to remember. These will eventually become variables in your sketch.

For example, if somebody pushes a 'call' button and then releases it, you probably want to remember that it has been pressed, because their need for a lift doesn't stop when they let go of the button.

I only provide help via the forum - please do not contact me for private consultancy.

Hi, i have an idea on how it will work but it's hard to translate that in program.

So, when I turn on the arduino, i would like a kind of Initialisation. So the lift checks that it's in the bottom of the structure (floor 0 ).

And, from that "point", it's waiting for a call. For example, the lift is at level 0, it's called at floor 2, it speeds up, and when it arrives at level 1,5 it speeds down and stops at floor 2.

Now, I imagine that the lift is moving, i have absolutely no idea how i can "rember" a push on a button WHILE the motor is turning.

thank you

EDIT: I also have to respect the priority. If the guy at floor 1 want to go at Floor 3 and that a guy in floor 2 also want to go to floor 3, so the lift has to stop at floor 2 before going to 3. So I suppose I will have a VAR for the direction

That's exactly the point Peter is making, and is why he's encouraging you to get the procedure clear in your head before you go anywhere near the IDE to start writing the program. Design first, construct second...

1) Initialisation at the Start of the arduino (Lift at level 0) (make the motor turning down while the lift is not at floor 0)2) Waiting a call- if just one call -> go to the correct floor - if there is another call -> verify if this guy want to go up or go down - if one guy is inside the lift and going in one direction (up for example) and that someone call the lift to go in the same direction, so the lift will stop to take this guy.

if one guy is inside the lift and going in one direction but that a guy is calling the lift to go down, so the guy inside has the priority.

Hi, i have an idea on how it will work but it's hard to translate that in programming.

So, when I turn on the arduino, i would like a kind of Initialisation. So the lift verify that it's in the bottom of the structure (floor 0 ).

What if it's not at floor 0 when you turn it on?

Quote

And, from that "point", it's waiting for a call. For example, the lift is at level 0, it's called at floor 2, it speeds up, and when it arrives at level 1,5 it speeds down and stops at floor 2.

now, i imagine that the lift is moving, i have absolutely no idea how i can "rember" a push on a button WHILE the motor is turning.

Set the motor runningStart checkingCheck the buttons and position switches (save the results in variables)Has lift reached the point where it needs to slow down?If it hasn't, go to start checkingIf it has, slow the motor.Has lift reached the floor?If it hasn't, go to start checkingIf it has, stop the motor, open the doorsNow see what buttons have been pressed and act on those.

Quote

EDIT: I also have to respect the priority. If the guy at floor 1 want to go at Floor 3 and that a guy in floor 2 also want to go to floor 3, so the lift has to stop at floor 2 before going to 3. So I suppose I will have a VAR for the direction of travel

And one for each position switch and one for each push button and one for each set of doors (to know whether they are open or shut).

Other things to think about are, if the lift is on, say, level 3, is empty and no buttons have been pressed, does it stay there or does it return to level 0? Do the doors stay open or do they close when the lift is inactive?

When the arduino is powered on, if the lift is already at floor 0, it doesn't move and if it's not at floor 0, the motor will turn while it's not at floor 0 (detected with a magnetic sensor).

Quote

And one for each position switch and one for each push button and one for each set of doors (to know whether they are open or shut).

I will receive the "state" of the doors in I2C, so il will receive a number from my PCF8574, translate that in binary and i will know the doors that are opened (0), closed(1), Unlocked(0), Locked(1)

Quote

Other things to think about are, if the lift is on, say, level 3, is empty and no buttons have been pressed, does it stay there or does it return to level 0? Do the doors stay open or do they close when the lift is inactive?

In a first time, i would like the lift to stay at the level where it stopped (no return if empty)

A thing that i dont understand is how, for exemple, to make tho motor speed down while I check the button.because you wrote that like "steps" but how to do that in the same time? How can i decrease the speed (PWM) in a loop WHILE I check the buttons?