I'm thinking about something like this:
os.loadAPI("button") -- load button api
os.loadAPI("parallel") -- load parallel api
m = peripheral.wrap("top") -- attaches a monitor to the top of the computer and calls the monitor 'm'
m.clear() -- clears the monitor
-- i will probably need global flags and variables here
function fillTable() -- initializes the table to be displayed on the monitor when this function is called
button.setTable("Floor 1", floor1, 10,20,3,5) -- these button locations are place holders
button.setTable("Floor 2", floor2, 22,32,3,5)
button.setTable("Floor 3", floor3, 10,20,8,10)
button.setTable("Floor 4", floor4, 22,32,8,10)
button.setTable("Floor 5", floor5, 10,20,13,15)
button.setTable("Cancel", cancel, 22,32,13,15)
end
function eleMoveUp()
-- code to determine if the elevator needs to go up and returns boolean
end
function eleMoveDown()
-- code to determine if the elevator needs to go down and returns boolean
end
function eleIdle()
-- code to see if elevator is currently doing something and returns boolean (using eleMoveUp and eleMoveDown functions)
-- returns true if BOTH eleMove* functions are false
end
function buttonPressed()
-- checks to see if elevator is already doing something (using eleIdle function)
-- if floor button is lower than current location it calls moveEleDown function
-- if floor button is higher than current location it calls moveEleUp function
-- if floor button is current location flash floor button using button api
-- if cancel button is pressed it returns nil
-- returns TARGET floor number
end
function elePosition()
-- parallel api for os.eventPull() OR sleep to see if elevator is on that floor
-- if elevator is on this computers floor broadcast to elevator network what floor the elevator is on
-- update floor monitor display using button api
end
function moveEleUp()
-- send redstone pulse to the up side of the elevator engine
end
function moveEleDown()
-- send redstone pulse to the down side of the elevator engine
end
function getComputerName()
-- returns string of the computer label
end
while true do
-- use button api to load monitor
-- use parallel api to ask each floor elevator for their label by rednet name and if the elevator is on their floor
--probably updating a global table of floor labels and assigning floor number to it
--I will also need to have it check for computer on the elevator to respond or it
--throws out an error
-- use parallel api to ask elevator control computer if they are moving up or down or idle
-- use button and parallel api to ask if a button has been pressed
-- if button is pressed, make sure elevator is idle and then find out if the elevator needs to go up or down
-- move elevator until target floor is reached
-- update button status (the floor that the elevator is on will be green, all others will be red, cancel button is gray)
end
I'm thinking I might need to break apart the buttonPressed function and use another function call to the moveEle* functions.