Added final elevator code.
This commit is contained in:
parent
80bb1986b2
commit
49ff45df7b
|
@ -5,41 +5,12 @@ A script for an all-in-one elevator with floor selection, sounds, doors, and
|
||||||
more.
|
more.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local SYSTEM_NAME = "Test Elevator"
|
-- Load floors from elevator settings.
|
||||||
|
local FLOORS = {}
|
||||||
-- Floors, in order from bottom to top.
|
local floorsFile = io.open("floors.tbl", "r") or error("Missing floors.tbl")
|
||||||
local FLOORS = {
|
FLOORS = textutils.unserialize(floorsFile:read("a"))
|
||||||
{
|
floorsFile:close()
|
||||||
label = "-1",
|
table.sort(FLOORS, function(fA, fB) return fA.height < fB.height end)
|
||||||
name = "Basement",
|
|
||||||
speaker = "speaker_2",
|
|
||||||
doorRedstone = "redstoneIntegrator_17",
|
|
||||||
contactRedstone = "redstoneIntegrator_18",
|
|
||||||
monitor = "monitor_4",
|
|
||||||
callMonitor = "monitor_5",
|
|
||||||
height = 25
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label = "0",
|
|
||||||
name = "Ground Floor",
|
|
||||||
speaker = "speaker_1",
|
|
||||||
doorRedstone = "redstoneIntegrator_7",
|
|
||||||
contactRedstone = "redstoneIntegrator_6",
|
|
||||||
monitor = "monitor_1",
|
|
||||||
callMonitor = "monitor_3",
|
|
||||||
height = 58
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label = "1",
|
|
||||||
name = "Mechanical Room",
|
|
||||||
speaker = "speaker_0",
|
|
||||||
doorRedstone = "redstoneIntegrator_4",
|
|
||||||
contactRedstone = "redstoneIntegrator_5",
|
|
||||||
monitor = "monitor_0",
|
|
||||||
callMonitor = "monitor_2",
|
|
||||||
height = 68
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local FLOORS_BY_LABEL = {}
|
local FLOORS_BY_LABEL = {}
|
||||||
for _, floor in pairs(FLOORS) do
|
for _, floor in pairs(FLOORS) do
|
||||||
|
@ -52,13 +23,18 @@ for _, floor in pairs(FLOORS) do
|
||||||
end
|
end
|
||||||
table.sort(FLOOR_LABELS_ORDERED, function(lblA, lblB) return FLOORS_BY_LABEL[lblA].height < FLOORS_BY_LABEL[lblB].height end)
|
table.sort(FLOOR_LABELS_ORDERED, function(lblA, lblB) return FLOORS_BY_LABEL[lblA].height < FLOORS_BY_LABEL[lblB].height end)
|
||||||
|
|
||||||
local CONTROL_BASE_RPM = 16
|
local settingsFile = io.open("settings.tbl", "r") or error("Missing settings.tbl")
|
||||||
local CONTROL_MAX_RPM = 256
|
local settings = textutils.unserialize(settingsFile:read("a"))
|
||||||
local CONTROL_ANALOG_LEVEL_PER_RPM = 2
|
|
||||||
|
|
||||||
local CONTROL_DIRECTION_UP = true
|
local SYSTEM_NAME = settings.systemName
|
||||||
local CONTROL_DIRECTION_DOWN = false
|
|
||||||
local CONTROL_REDSTONE = "redstoneIntegrator_13"
|
local CONTROL_BASE_RPM = settings.control.baseRpm
|
||||||
|
local CONTROL_MAX_RPM = settings.control.maxRpm
|
||||||
|
local CONTROL_ANALOG_LEVEL_PER_RPM = settings.control.analogLevelPerRpm
|
||||||
|
|
||||||
|
local CONTROL_DIRECTION_UP = settings.control.directionUp
|
||||||
|
local CONTROL_DIRECTION_DOWN = settings.control.directionDown
|
||||||
|
local CONTROL_REDSTONE = settings.control.redstone
|
||||||
|
|
||||||
local CURRENT_STATE = {
|
local CURRENT_STATE = {
|
||||||
rpm = nil,
|
rpm = nil,
|
||||||
|
@ -66,11 +42,11 @@ local CURRENT_STATE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local function openDoor(floor)
|
local function openDoor(floor)
|
||||||
peripheral.call(floor.doorRedstone, "setOutput", "back", true)
|
peripheral.call(floor.redstone, "setOutput", "left", true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function closeDoor(floor)
|
local function closeDoor(floor)
|
||||||
peripheral.call(floor.doorRedstone, "setOutput", "back", false)
|
peripheral.call(floor.redstone, "setOutput", "left", false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function playChime(floor)
|
local function playChime(floor)
|
||||||
|
@ -133,7 +109,7 @@ local function setSpeed(rpm)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function isFloorContactActive(floor)
|
local function isFloorContactActive(floor)
|
||||||
return peripheral.call(floor.contactRedstone, "getInput", "back")
|
return peripheral.call(floor.redstone, "getInput", "back")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Determines the label of the floor we're currently on.
|
-- Determines the label of the floor we're currently on.
|
||||||
|
@ -141,7 +117,7 @@ end
|
||||||
-- If that fails, the elevator is at an unknown position, so we move it as soon as possible to top.
|
-- If that fails, the elevator is at an unknown position, so we move it as soon as possible to top.
|
||||||
local function determineCurrentFloorLabel()
|
local function determineCurrentFloorLabel()
|
||||||
for _, floor in pairs(FLOORS) do
|
for _, floor in pairs(FLOORS) do
|
||||||
local status = peripheral.call(floor.contactRedstone, "getInput", "back")
|
local status = isFloorContactActive(floor)
|
||||||
if status then return floor.label end
|
if status then return floor.label end
|
||||||
end
|
end
|
||||||
-- No floor found. Move the elevator to the top.
|
-- No floor found. Move the elevator to the top.
|
|
@ -0,0 +1,65 @@
|
||||||
|
{
|
||||||
|
{
|
||||||
|
label = "1",
|
||||||
|
name = "First Floor",
|
||||||
|
speaker = "speaker_0",
|
||||||
|
redstone = "redstoneIntegrator_4",
|
||||||
|
monitor = "monitor_1",
|
||||||
|
callMonitor = "monitor_0",
|
||||||
|
height = 126
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label = "2",
|
||||||
|
name = "Second Floor",
|
||||||
|
speaker = "speaker_1",
|
||||||
|
redstone = "redstoneIntegrator_6",
|
||||||
|
monitor = "monitor_3",
|
||||||
|
callMonitor = "monitor_2",
|
||||||
|
height = 140
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label = "3",
|
||||||
|
name = "Third Floor",
|
||||||
|
speaker = "speaker_2",
|
||||||
|
redstone = "redstoneIntegrator_7",
|
||||||
|
monitor = "monitor_5",
|
||||||
|
callMonitor = "monitor_4",
|
||||||
|
height = 147
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label = "4",
|
||||||
|
name = "Fourth Floor",
|
||||||
|
speaker = "speaker_3",
|
||||||
|
redstone = "redstoneIntegrator_8",
|
||||||
|
monitor = "monitor_6",
|
||||||
|
callMonitor = "monitor_7",
|
||||||
|
height = 154
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label = "5",
|
||||||
|
name = "Fifth Floor",
|
||||||
|
speaker = "speaker_4",
|
||||||
|
redstone = "redstoneIntegrator_9",
|
||||||
|
monitor = "monitor_8",
|
||||||
|
callMonitor = "monitor_9",
|
||||||
|
height = 161
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label = "6",
|
||||||
|
name = "Sixth Floor",
|
||||||
|
speaker = "speaker_5",
|
||||||
|
redstone = "redstoneIntegrator_10",
|
||||||
|
monitor = "monitor_10",
|
||||||
|
callMonitor = "monitor_11",
|
||||||
|
height = 168
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label = "7",
|
||||||
|
name = "Seventh Floor",
|
||||||
|
speaker = "speaker_6",
|
||||||
|
redstone = "redstoneIntegrator_11",
|
||||||
|
monitor = "monitor_12",
|
||||||
|
callMonitor = "monitor_13",
|
||||||
|
height = 175
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
systemName = "HandieVale Tower",
|
||||||
|
control = {
|
||||||
|
baseRpm = 16,
|
||||||
|
maxRpm = 256,
|
||||||
|
analogLevelPerRpm = 2,
|
||||||
|
directionUp = true,
|
||||||
|
directionDown = false,
|
||||||
|
redstone = "redstoneIntegrator_5"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue