Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Config
- modemPos = "top"
- startLevel = 1000000
- stopLevel = 100000
- local gen = peripheral.wrap("right")
- rednet.open(modemPos)
- local powerSpace = "No message received"
- function screen()
- term.clear()
- local title = "DiselGen2 Control by _TheSettler_"
- local l1 = "Unfilled energy capacity: "
- local xLen1 = string.len(title)
- local xLen2 = string.len(l1)
- local xLen3 = string.len(powerSpace)
- local xPos = (51-xLen1)/2
- term.setCursorPos(xPos, 2)
- print(title)
- local xPos = (51-xLen2)/2
- term.setCursorPos(xPos, 6)
- print(l1)
- local xPos = (51-xLen3)/2
- term.setCursorPos(xPos,7)
- print(powerSpace)
- end
- function getUpdate()
- senderID, message, protocol = rednet.receive()
- if protocol == "Settler" then
- term.setCursorPos(1,12)
- powerSpace = message
- end
- end
- function isNumeric(value)
- if tonumber(value) ~= nil then
- return true
- else
- return false
- end
- end
- function getState()
- if isNumeric(powerSpace) then
- if powerSpace > startLevel then
- status = "Activated"
- term.setCursorPos(1,10)
- end
- if powerSpace < stopLevel then
- status = "Deactivated"
- term.setCursorPos(1,10)
- end
- else
- status = "Error"
- end
- if status == "Activated" then
- gen.setEnabled(true)
- else
- gen.setEnabled(false)
- end
- end
- while true do
- screen()
- getUpdate()
- getState()
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement