· 3 years ago · Jun 23, 2022, 08:50 PM
1-- What we want to achieve
2
3-- We need an elevator system with a few things
4-- - Normal up and down elevator controls on ele
5-- - Call feature
6
7-- To get the normal up and down feature, we use an alalog lever.
8-- The alalog lever emits a signal strength as shown on the tube above (0-15?)
9-- The signal will then be our "goto" floor represented by an int
10-- Adjacent to the analog lever is a button. Upon pressing the button, the actual "move" signal will be sent.
11-- Upon "move" being sent, the elevator will find the direction by comparing the "current" floor to the "goto" floor.
12-- After the direction is found, the elevator will move to this position until a signal(emitted wirelessly from a modem), which contains the "current", and the "goto" floor are the same.
13-- When the disired floor is reached, a clutch will be activated stopping the system.
14-- (The system must always be in idle!)
15
16local id = os.getComputerID()
17print("ID: " .. id)
18
19
20-- We'll need a way to set data
21-- setting data and reading data
22-- for this we'll use fs and store data in files
23
24function setData()
25 -- check if a "data" file exists, if not, create one
26 while fs.exists("data") ~= true do
27 -- set background color to green to show that we're in the data collection process
28 term.setBackgroundColor(8192)
29
30 -- opening file as write; data is stored here
31 local file = fs.open("data", "w")
32
33 -- collect elevator data
34 term.write("Number of Floors: ")
35 floors = tonumber(read())
36
37 term.write("Current Floor: ")
38 currentFloor = tonumber(read())
39
40 -- compile data into table
41 local elevatorData = {floors, currentFloor}
42 term.write("Final Data = " .. elevatorData)
43
44 -- write data to file which can be called later.
45 file.write(elevatorData)
46 file.close()
47 end
48end
49
50setData()