Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component=require("component")
- local serial=require("serialization")
- local reactor=component.br_reactor
- local modem=component.modem
- local event=require("event")
- modem.open(1)
- local send_addr=nil
- local this_addr=nil
- local testing=true
- while testing do
- local _,addr,from,port,_,msg=event.pull("modem_message")
- print(from..":"..msg)
- if msg=="test" then
- testing=false
- send_addr=from
- this_addr=addr
- end
- end
- local function update()
- modem.send(send_addr,1,serial.serialize({
- ["energy"]=reactor.getEnergyStored()/100000,
- ["rodLevel"]=reactor.getControlRodLevel(1),
- ["auto"]=automatic}))
- end
- local ended=false
- modem.send(send_addr,1,"test")
- local automatic=false
- function listen()
- local evt,_,from,port,_,msg=event.pull(5,"modem_message")
- if not evt==nil then
- print(from..":"..msg)
- if msg=="on" then
- reactor.setActive(true)
- automatic=false
- end
- if msg=="off" then
- reactor.setActive(false)
- automatic=false
- end
- if msg=="end" then
- reactor.setActive(false)
- ended=true
- end
- if msg=="auto" then
- automatic=true
- end
- if msg=="man" then
- automatic=false
- end
- if string.sub(msg,1,2)=="up" then
- automatic=false
- reactor.setAllControlRodLevels(min(100,reactor.getControlRodLevel(1)+string.sub(msg,3,string.len(msg))))
- end
- if string.sub(msg,1,4)=="down" then
- automatic=false
- reactor.setAllControlRodLevels(max(0,reactor.getControlRodLevel(1)-string.sub(msg,5,string.len(msg))))
- end
- end
- end
- coroutine.create(listen)
- while not ended do
- if automatic then
- reactor.setAllControlRodLevels(reactor.getEnergyStored()/10000)
- end
- -- update()
- -- coroutine.create(listen)
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement