Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = peripheral.wrap("top")
- local states = {}
- rednet.open("back")
- m.clear()
- m.setBackgroundColor(colors.gray)
- m.setTextColor(colors.black)
- m.setCursorPos(1,1)
- m.setBackgroundColor(colors.orange)
- m.write("Automated Farm")
- m.setBackgroundColor(colors.gray)
- m.setCursorPos(1,3)
- m.setBackgroundColor(colors.cyan)
- m.write("Seed States:")
- m.setBackgroundColor(colors.gray)
- m.setTextColor(colors.white)
- function string.starts(String,Start)
- return string.sub(String,1,string.len(Start))==Start
- end
- function formatCmd(cmd)
- local formatted = {}
- local y = 0
- for x in string.gmatch(cmd, "%S+") do
- y = y+1
- formatted[y] = x
- end
- return formatted
- end
- function validCmd(cmd)
- if string.starts(cmd,"STATE") == true then
- return true
- else
- return false
- end
- end
- function populateStates(fill)
- for i = 1, 18, 1 do
- if i % 2 == 0 then
- m.setCursorPos(4,4+i/2-1)
- if fill[i] == "X" then
- m.setBackgroundColor(colors.red)
- else
- m.setBackgroundColor(colors.green)
- end
- m.write(fill[i])
- m.setBackgroundColor(colors.gray)
- else
- m.setCursorPos(2,4+i/2)
- if fill[i] == "X" then
- m.setBackgroundColor(colors.red)
- else
- m.setBackgroundColor(colors.green)
- end
- m.write(fill[i])
- m.setBackgroundColor(colors.gray)
- end
- end
- end
- function init()
- for j = 1, 18, 1 do
- states[j] = "X"
- end
- end
- function listen(fromid, debug)
- local sid, msg, protocol = rednet.receive(fromid)
- if debug == true then
- print("Message received!")
- print("SID: " .. tostring(sid))
- print("MSG: " .. tostring(msg))
- print("PRT: " .. tostring(protocol))
- print("=================")
- for k,v in pairs(formatCmd(msg)) do
- print(k .. " - " .. v)
- end
- end --debug
- if validCmd(msg) == true then
- local a = formatCmd(msg)[2]
- local b = formatCmd(msg)[3]
- if b == "0" then
- states[tonumber(a)] = "X"
- else
- states[tonumber(a)] = "v"
- end
- populateStates(states)
- listen(15,false)
- else
- print("No valid command received")
- shell.run("reboot")
- end
- end
- init()
- populateStates(states)
- listen(15,false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement