Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- watty = 0.200
- local monitor = peripheral.wrap( "right" )
- local ModemPos = "top"
- local vstup = "left"
- local server = 89
- --------------------------------------------------------------------------
- stav = false
- historie = false
- dcas = 0
- cykl = 0
- cas1 = 0
- sazba = 4.5
- local MyID = os.getComputerID()
- modem = peripheral.wrap(ModemPos)
- modem.open(MyID)
- if fs.exists("/stav") then
- local f = fs.open("/stav", "r")
- suma = tonumber(f.readLine())
- cykly = tonumber(f.readLine())
- f.close()
- else
- suma = 0
- cykly = 0
- end
- function odeslat()
- modem.transmit(tonumber(server),8080,MyID)
- modem.transmit(tonumber(server),8081,suma)
- end
- function vypis()
- monitor.setTextScale(0.5)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Tar: "..watty.."kW/t")
- monitor.setCursorPos(1,3)
- monitor.write("+ "..((watty*dcas)).." W")
- monitor.setCursorPos(1,5)
- monitor.write("Tick: "..dcas)
- monitor.setCursorPos(1,7)
- monitor.write("Sum: ")
- if (suma<1000) then
- monitor.write(suma.." W")
- elseif (suma >= 1000 and suma < 1000000) then
- monitor.write((math.floor(suma/1000)).." kW")
- elseif (suma>= 1000000 and suma <1000000000) then
- monitor.write((math.floor(suma/1000/1000)).." MW")
- elseif (suma>= 1000000000 and suma <1000000000000) then
- monitor.write((math.floor(suma/1000/1000)).." GW")
- elseif (suma>= 1000000000000 and suma <1000000000000000) then
- monitor.write((math.floor(suma/1000/1000)).." TW")
- end
- monitor.setCursorPos(1,9)
- monitor.write("Cena: "..(math.floor(suma/1000*sazba)).."MC")
- end
- function vypocet()
- suma = math.floor((suma +watty*dcas)*100)
- suma = suma/100
- cykly = cykly + 1
- local f = fs.open("/stav", "w")
- f.writeLine(suma)
- f.writeLine(cykly)
- f.close()
- odeslat()
- vypis()
- end
- function loop()
- if (redstone.getInput(vstup)) then
- stav = true
- else
- stav = false
- end
- if not (historie == stav) then
- if stav then
- cas1 = (os.time() * 1000 + 18000)%24000
- else
- cas2 = (os.time() * 1000 + 18000)%24000
- dcas = cas2-cas1
- if (dcas<0) then dcas = 0 end
- vypocet()
- end
- historie = stav
- elseif cykl == 99 and stav then
- cas2 = (os.time() * 1000 + 18000)%24000
- dcas = cas2-cas1
- if (dcas<0) then dcas = 0 end
- vypocet()
- cas1 = (os.time() * 1000 + 18000)%24000
- print (dcas)
- sleep(1)
- end
- cykl = cykl+1
- if (cykl >= 100) then os.reboot() end
- sleep (0.1)
- loop()
- end
- term.clear()
- term.write(tostring(MyID))
- loop()
Add Comment
Please, Sign In to add comment