um looking for elevator avr program. Do you have example program ?

I have to write a project for 30 floors.  but Im not good for programming... If u can write me example program for 2 floors . Include limiting switch, Door open, Door close . display floor number and  Other parameters.  So I can study the code and the i Can expand it to my project.

You'll only get better at programming by practicing, not taking apart code you don't understand.

Start simple,
Build up.

orksecurity6 years ago

Think about it as a state machine. Add timing loops to handle the hold-door-open period.
Note that the only way you get better at programming is to practice. That means doing it yourself, rather than getting others to do it for you. Asking for a few hints is reasonable; asking folks to write it for you really isn't .
frollard6 years ago
I won't write it in actual code, but basically it needs to do several things in a loop: I've rather lazily and intentionally left some glaring logic errors in this code but it gets you started at least. :)

define ascendordescendMode

setup function:
moveelevator(home floor)
carlocation= 0 // incremental encoder moves car up in 100ths of a floor, 0=bottom floor, 0.50 is between 1st and 2nd. you're considered at a floor when location is within 1/100 of a whole number.
ascendordescendMode = ascend
number of floors = x (extra credit: most buildings don't have a 13th floor)
end setup function

// listen = save the value of any inputs to a variable
Main loop:
listen for up call buttons>> add to array of up stops
listen for down call buttons>> add to down stops
listen for floor buttons >> add to array of up or down stops based on current location (greater than or less than current)
listen for limit switches (top or bottom of shaft)
listen for floor number switches/encoder
listen for emergency stop

if emergencystop then stop and wait or do whatever;
target floor = 0
if upstops list is empty, ascend mode = descend
if downstops list is empty, ascend mode = ascend
if upstops and downstops list is empty, ascend mode = attend
if ascendmode = ascend
sort array of stops.ascending
target floor= first element in ascend stops that is greater than current location
gotofloor(target floor)
esleif ascendmode = descend
target floor = first element in descend stops that is less than current location
if ascendmode = attend
target floor = 0
gotofloor(target floor)

end ascend mode if

procedure opendoor()
if stopped and stoppedatAfloor then
while door limit switch = 0
turn on door open motor
end while
end if
end function

procedure closedoor()
//consider always willing to CLOSE the door, even when between floors
while doorclose limit switch = 0
turn on door close motor
end while
end function

procedure gotoFloor(floor number)
i bet you can figure this part out.

end procedure

procedure GoUp()
if not top limit switch
set motor to go up
speed is target location- current location maxed at 1, as you get closer you slow down.
end if
end procedure

procedure goDown()
if not bottom limit switch
set motor to go down
speed is current location - target location maxed at 1.
end if
end procedure